What is Maximum Subarray
Find the contiguous slice with the largest sum. A subarray means consecutive indices — not a subsequence. Kadane keeps a running best ending at the current index. If extending hurts, start fresh from here.
currentSum = max(arr[i], currentSum + arr[i])maxSum = max(maxSum, currentSum)Approach
Visualization & Algorithm Execution
-
-
-
[-, -]
Understanding the Algorithm
nums[i] is better than current+nums[i], restart from here.Implementation