← All problems

Maximum Subarray

Medium arraysdynamic programming LeetCode ↗
Find the contiguous subarray with the largest sum and return that sum.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(1)

Common pitfalls

  • Resetting cur to 0 breaks all-negative arrays
  • Confusing 'ending here' with 'anywhere'

Your solution

Log in to save your code and track progress.