Problem
You get an array of integers nums. A subarray is a part of the array with one or more consecutive items.
Find the subarray with the largest sum, and return that sum.
Example 1
- Input:
- nums = [3,-5,4,-1,2,-6,1]
- Output:
- 5
- Explanation:
- The subarray
[4, -1, 2]has the sum 5. No other subarray has a larger sum.
Example 2
- Input:
- nums = [-7]
- Output:
- -7
- Explanation:
- The array has one item, so the only subarray is
[-7].
Example 3
- Input:
- nums = [2,3,-1,8]
- Output:
- 12
- Explanation:
- The full array is the best subarray. Its sum is
2 + 3 - 1 + 8, which is 12.
Constraints
- 1 <= nums.length <= 10^5
- -10^4 <= nums[i] <= 10^4
Follow-up
Find a solution that runs in O(n) time. Then try a divide and conquer solution, which splits the array into two halves and solves each half.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Maximum Product Subarray
Coding · Array · Dynamic Programming
- Maximum Profit in Job Scheduling
Coding · Array · Binary Search · Dynamic Programming
- Maximum Sum of Two Non-Overlapping Subarrays
Coding · Array · Dynamic Programming · Sliding Window
- Partition Array for Maximum Sum
Coding · Array · Dynamic Programming
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 6 records
LinkedIn
Leetcode 53. Maximum Subarray
Reported Sep 16, 2025 · 4 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceMeta
Leetcode 53. Maximum Subarray
Reported Mar 24, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 53. Maximum Subarray
Reported Nov 5, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceTesla
Leetcode 53. Maximum Subarray
Reported Jul 15, 2025 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View source