Given an integer array `nums`, find the contiguous subarray with the largest sum and return that sum.
Examples
Input
nums = [-2,1,-3,4,-1,2,1,-5,4]
Output
6
Subarray [4,-1,2,1] has sum 6.
Constraints
- 1 <= nums.length <= 10⁵
- -10⁴ <= nums[i] <= 10⁴
Given an integer array `nums`, find the contiguous subarray with the largest sum and return that sum.
nums = [-2,1,-3,4,-1,2,1,-5,4]
6
Subarray [4,-1,2,1] has sum 6.
Explore step-by-step interactive animations, memory state tracking, and live multi-language execution in DrawCode.
Launch Interactive Visualizer