Data Structures & AlgorithmsModerateProduct placement · Amazon/Microsoft

An equilibrium index i has (sum of elements left of i) = (sum of elements right of i), excluding a[i]. Which indices of [−4, 5, 8, −4, −4, 1, −4, 7, 1] (0-based) are equilibrium indices?

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

Correct answer: B. 4

Total = 6. Scan with a running left sum L: index i works when L = total − L − a[i]. That holds at 4.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic