Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximum Subarray

XPChallenge Points: 20
levelLevel: Medium

You are given an integer array nums.
Your task is to find the maximum possible sum of any contiguous subarray within nums.
Return this maximum sum value.

Example 1:

Input: nums = [-3, 2, -1, 4, -2, 2]

Output: 5

Explanation:

The subarray [2, -1, 4] has the largest sum 5.

Example 2:

Input: nums = [8, -1, 3, 4]

Output: 14

Explanation:

The subarray [8, -1, 3, 4] gives the sum 14.

Example 3:

Input: nums = [-5, -2, -3]

Output: -2

Explanation:

The subarray [-2] has the maximum sum -2.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result