Maximum Sum Circular Subarray
Given a circular integer array nums, find the maximum possible sum of a non-empty subarray.
A circular array means the element after the last element is the first element.
A subarray can wrap around from the end of the array back to the beginning.
Return the maximum subarray sum.
Example 1
Input
n = 3 nums = [1, -2, 3]
Output
4
Explanation
The maximum circular subarray is:
[3, 1]
Its sum is:
3 + 1 = 4
The subarray wraps from the last element back to the first element.
Example 2
Input
n = 5 nums = [5, -3, 5, 1, -2]
Output
8
Explanation
The maximum subarray is:
[5, -3, 5, 1]
with sum:
5 - 3 + 5 + 1 = 8
Constraints
Hints:
Hint 1
There are two possibilities:
- The maximum subarray does not wrap around.
- The maximum subarray does wrap around.
Hint 2
For the wrapping case:
maximum circular sum = total sum - minimum subarray sum
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 22, 2026
Last updated
Aug 22, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output