โœ๏ธ

Maximum Subarray

Medium๐Ÿท๏ธ Dynamic programming๐Ÿ“‚ Greedy & Dynamic Programming
๐Ÿงฉ The problem

Return the largest sum of any non-empty contiguous subarray.

Examples

  • [-2, 1, -3, 4, -1, 2, 1, -5, 4] โ†’ 6 (the subarray [4, -1, 2, 1])

๐ŸŽฏ Aim for: O(n) time ยท O(1) space (Kadaneโ€™s algorithm)

โœ๏ธ Write your solution

Pick a language, press Run to try it, then Run tests to check it against every test case โ€” just like a coding interview.

โ† All practice problems