4 / 75
Use Kadane's algorithm: track max ending here and global max.
Example:
Input:
[-2,1,-3,4,-1,2,1,-5,4]Output:
6Common Mistakes:
- Off-by-one indexing
- Not handling edge cases (null/empty)
Notes:
Edge cases: duplicates, empty inputs, negative numbers where applicable.
💻
Java Solution Hidden
Enable “Show Full Solution” to view the code
Use Kadane's algorithm: track max ending here and global max.
Example:
Input:
[-2,1,-3,4,-1,2,1,-5,4]Output:
6Common Mistakes:
- Off-by-one indexing
- Not handling edge cases (null/empty)
Notes:
Edge cases: duplicates, empty inputs, negative numbers where applicable.
4/75
Maximum Subarray