Data Structures & AlgorithmsVery hard

For 3 1 4 1 5 9 2 6, find the smallest 0-based index t such that the sum of the elements A[0..t] is MORE than half of the total sum of the array. Give t.

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

Correct answer: B. 5

Scan the prefix sums and stop at the first one whose doubled value exceeds the total, which compares the running sum with half the array sum without fractions. Taking the element count above half, or off-by-one indices, gives different answers.

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

Exams that ask this topic