docs(docs): add O(n) Kadane implementation for Maximum Subarray solution

This commit is contained in:
Prad Nukala committed 2026-09-29 13:22:24 -04:00
1 parent e63d517c9a
commit 667bc06965
1 file changed
+10
@@ -40,4 +40,14 @@ If you have figured out the O(n) solution, try coding another solution using the
```py
class Solution:
def maxSubArray(self, nums: list[int]) -> int:
best, total = nums[0], nums[0]
for i in range(1, len(nums)):
if total < 0:
total = nums[i]
else:
total = total + nums[i]
best = max(best, total)
return best
```