Skip to content
Decoder

Maximum Sum Circular Subarray

Medium

Problem

nums is circular: after the last element comes the first one again. Return the largest sum of a non-empty run of neighbouring elements. A run may wrap around the end, but it may use each element at most once.

Example 1

Input
nums = [1, -2, 3, -2]
Output
3
Why
just [3]

Example 2

Input
nums = [5, -3, 5]
Output
10
Why
5, then wrap to 5

Example 3

Input
nums = [-3, -2, -3]
Output
-2
Why
you must take at least one

Constraints

  • n == nums.length
  • 1 <= n <= 3 * 10^4
  • -3 * 10^4 <= nums[i] <= 3 * 10^4

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.