Data Structures & AlgorithmsVery hardCodeforces Div2 C · GATE CS

What is the maximum sum of a non-empty contiguous subarray of the CIRCULAR array [5, -3, 5, -2, 7, -6, 4]? A subarray may wrap from the last element around to the first.

  1. A. 16
  2. B. 12
  3. C. 10
  4. D. 11

Correct answer: A. 16

Two cases: the best segment does not wrap (plain Kadane), or it wraps, which equals total sum minus the minimum non-empty subarray. Taking the larger of the two handles both; plain Kadane alone misses the wrap-around case.

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

Exams that ask this topic