r/leetcode • u/JacketFearless1805 • 13d ago
Intervew Prep Day 25: revisited Kadane’s Algorithm — way simpler than back in 2nd year
Hey everyone,
I finished Day 25 today. I kept the session focused on Maximum Subarray Sum using Kadane’s Algorithm.
The first time I learned Kadane’s Algorithm back in my second year of college, deciding when to reset the running sum felt weirdly unintuitive. Revisiting it today, the core greedy insight felt completely natural:
- Drop Negative Carryover: Maintain a running sum as you iterate through the array. Whenever the running sum drops below zero, carrying it forward only drags down future subarrays, so you reset it to zero immediately.
- Track the Global Maximum: Update the maximum sum at every step before resetting, which cleanly handles edge cases where every element in the array is negative.
It is satisfying to see concepts that used to feel tricky in college become effortless O(n) time and O(1) space instincts.
See you guys tomorrow for Day 24!
5
Upvotes
2
u/yourlimit 12d ago
Cool dude. How do you decide which problems or topics for the day? I saw your other posts as well. Your consistency is inspiring