Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

For the circular array [5, -3, 4, -6, 2, 3, -1, 4], what is the maximum sum of a non-empty subarray when the array is treated as circular (a subarray may wrap from the end back to the start)?

  1. A. 8
  2. B. 15
  3. C. 14
  4. D. 13

Correct answer: C. 14

Either the best subarray does not wrap (plain Kadane) or it wraps, and then its complement is the minimum-sum non-empty subarray, so the answer is total minus min subarray. Using total minus the minimum element is a trap.

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

Exams that ask this topic