Panda Guru LogoPanda
Guru

Online Assessment Coding Task: Reduce an array to a single element using the following operations

Round 1

Questions: The goal is to reduce an array to a single element using the following operations:

  1. Remove the leftmost element: [1, 2, 3] -> [2, 3].
  2. Remove the rightmost element: [1, 2, 3] -> [1, 2].
  3. Remove any middle element. In this case, the middle element and its neighbors are replaced with the sum of the neighbors: [1, 2, 3] -> [4], where 4 = 1 + 3 and 2 is removed.

The objective is to maximize the value of the single remaining element after applying any sequence of these operations.

Example 1:

arr = [2, 1, -3, 5], max = 6 1. replace [1, -3, 5] -> 6, new arr = [2, 6] 2. delete leftmost element 2, get max element = 6

Example 2:

arr = [2, 1, -3, 5, 8], max = 10 1. replace [1, -3, 5] -> 6, new arr = [2, 6, 8] 2. replace [2, 6, 8] -> 10, get max element = 10
Candidate's Approach

No approach provided.

Interviewer's Feedback

No feedback provided.