Description
Given a circular integer array nums, find the maximum possible sum of a non-empty subarray of nums. A circular array wraps around, so the next element of nums[n-1] is nums[0].
Examples
Input:
nums = [1,-2,3,-2]Output:
3Explanation:
Subarray [3] has maximum sum 3.
Input:
nums = [5,-3,5]Output:
10Explanation:
Circular subarray [5,5] wrapping around has sum 10.
Input:
nums = [-3,-2,-3]Output:
-2Explanation:
Works with negative numbers.
Constraints
- •
n == nums.length - •
1 ≤ n ≤ 3 × 10⁴ - •
-3 × 10⁴ ≤ nums[i] ≤ 3 × 10⁴