Data Structures & AlgorithmsVery hardTCS Digital · Product companies

What is the maximum sum of a non-empty subarray in the circular array [8, -8, 9, -9, 10, -11, 12], where the subarray may wrap from the end to the start?

  1. A. 22
  2. B. 12
  3. C. 20
  4. D. 39

Correct answer: A. 22

The best non-wrapping subarray is 12 (Kadane). With wrapping, answer = total - minimum subarray = 11 - (-11) = 22, from the wrapped block 12, 8, -8, 9, -9, 10. Summing all positives (39) is not a contiguous block.

More Coding Interview Problems questions

Exams that ask this topic