Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT

How many indices i of [2, 2, 0, 2, 2] have the sum of the elements strictly to the left of i equal to the sum of the elements strictly to the right of i? (The element at i itself is excluded from both sides.)

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

Correct answer: B. 1

Compare the left prefix with total minus left prefix minus a[i]; the element at i is in neither side. Requiring the left prefix to match the right side including a[i] is a different test.

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

Exams that ask this topic