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

For a = [2, -1, 4, -3, 5], which of the following statements is TRUE? A. Some contiguous subarray sums to 7. B. Every prefix sum from the second one onward is at least 2. C. The maximum subarray sum is 9. D. No contiguous subarray sums to 0.

  1. A. Some contiguous subarray sums to 7.
  2. B. Every prefix sum from the second one onward is at least 2.
  3. C. The maximum subarray sum is 9.
  4. D. No contiguous subarray sums to 0.

Correct answer: A. Some contiguous subarray sums to 7.

Prefix sums are 0, 2, 1, 5, 2, 7. The subarray [2, -1, 4, -3, 5] sums to 7, which is the only true statement; the minimum prefix from the second onward is 1, the maximum subarray sum is 7 rather than 9, and the subarray [4, -3, 5] style checks reveal a zero sum from -1 + 4 - 3.

More Coding Interview Problems questions

Exams that ask this topic