Maximum Subarray

Given an integer array nums, find the subarray with the largest sum and return its sum. The subarray must contain at least one element. This is the classic application of Kadane's algorithm and a fundamental DP pattern.

Examples
Input: [-2,1,-3,4,-1,2,1,-5,4]
Output: 6
Hints
Related Problems

Maximum Subarray

Given an integer array nums, find the subarray with the largest sum and return its sum. The subarray must contain at least one element. This is the classic application of Kadane's algorithm and a fundamental DP pattern.