Problem
This problem was asked by Facebook.
Given a circular array, compute its maximum subarray sum in O(n) time. A subarray can be empty, and in this case the sum is 0.
For example, given
[8, -1, 3, 4]
, return15
as we choose the numbers3
,4
, and8
where the8
is obtained from wrapping around.Given
[-4, 5, 1, 0]
, return6
as we choose the numbers5
and1
.
Example 1:
Example 2:
Example 3:
what do we need?
iterate
track sum?
Last updated