GATE Computer ScienceHardGATE CS (PYQ pattern)

What is the maximum possible sum of a non-empty contiguous circular subarray of A = [6, −4, −7, 5, 3, −2, 8, −6, 4, −1] (the array is circular, so a subarray may wrap from the end to the start)?

  1. A. 14
  2. B. 20
  3. C. 12
  4. D. 17

Correct answer: D. 17

Kadane gives 14 for the ordinary best subarray (5, 3, −2, 8). A wrapping subarray equals total − (minimum subarray) = 6 − (−11) = 17, achieved by the wrapping window 5, 3, −2, 8, −6, 4, −1, 6; brute force over all circular windows confirms 17.

More Algorithms questions

Exams that ask this topic