Data Structures & AlgorithmsVery hard

How many indices i satisfy: the sum of the elements before i equals the sum of the elements after i, excluding P2[i] itself? (P2 = [1, 2, 3, 0, 3, 2, 1])

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

Correct answer: B. 1

Pivot index test: prefix sum before i must equal suffix sum after i, and the pivot element is in neither part. Including the pivot on either side changes the equation and yields a different count.

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

Exams that ask this topic