Data Structures & AlgorithmsHardAmazon · Microsoft coding round

For the circular array [5, -3, 5, -2, 6, -8, 4], what is the maximum sum of a non-empty contiguous subarray when the subarray is allowed to wrap around the end?

  1. A. 11
  2. B. 15
  3. C. 13
  4. D. 7

Correct answer: B. 15

The best non-wrapping subarray is 5, -3, 5, -2, 6 = 11. Wrapping gives total − (minimum subarray) = 7 − (−8) = 15, the subarray [4, 5, -3, 5, -2, 6].

More Coding Interview Problems questions

Exams that ask this topic