Maximum Subarray (Kadane's)
00:00
AmazonMicrosoft
Find the contiguous subarray with the largest sum (at least one element) and return its sum. This is the classic Kadane's algorithm problem.
Examples
Input → [-2,1,-3,4,-1,2,1,-5,4]
Output → 6
Note: subarray [4,-1,2,1]
Input → [1]
Output → 1
Input → [5,4,-1,7,8]
Output → 23
Note: entire array