#918
Maximum Sum Circular Subarray
specialist · 875 · lc medium +31 · verified · 49.5% accepted · 7,297 likes · top 36%
Description
Given a circular integer array nums where the tail connects back to the head, return the maximum sum of any non-empty contiguous subarray, including subarrays that wrap around from the end back to the beginning.
Example 1:
Input: nums = [1,-2,3,-2]
Output: 3
Explanation: Subarray [3] has maximum sum 3.
Example 2:
Input: nums = [5,-3,5]
Output: 10
Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10.
Example 3:
Input: nums = [-3,-2,-3]
Output: -2
Explanation: Subarray [-2] has maximum sum -2.
Code
1
2
3