Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

Array a = [2, 1, -1, 4, -2, 3, 0, 1, 1, 0, 2]. How many indices i have the sum of the elements strictly left of i equal to the sum of the elements strictly right of i? Element a[i] itself is excluded from both sides.

  1. A. 0
  2. B. 1
  3. C. 2
  4. D. 5

Correct answer: B. 1

Let P be the prefix sum. The condition is P[i] = total - P[i] - a[i], which excludes the pivot element. Including a[i] on one side is the common error and changes the count.

More Coding Interview Problems questions

Exams that ask this topic