1212. Maximum Sum Circular Subarray

MediumDynamic ProgrammingPartition DP

Given a circular array nums (the end wraps to the beginning), return the largest sum of any non-empty subarray, where a subarray may wrap around but uses each element at most once. The input is JSON {nums}.

Input: JSON {nums}.

Output: Integer — the maximum circular subarray sum.

Examples

Example 1
Input: {"nums":[1,-2,3,-2]}
Output: 3
Explanation: [3] alone.
Example 2
Input: {"nums":[5,-3,5]}
Output: 10
Explanation: Wraps around: 5 + 5.
Example 3
Input: {"nums":[-3,-2,-3]}
Output: -2
Explanation: All negative; take the largest.

Constraints

Asked by

InfosysAmazonGoogleMetaMicrosoftApple
Solve this problem in the editor →