Yinka Ashafa’s Post

Earlier this week, I wrote about the developer loop - learn, practice, apply, repeat. So I put it into practice. Just staying sharp, working through DSA problems in Python. Came across max_subarray_sum. Solved it. Moved on. Then I went back to see how other people approached it… and ran into Kadane’s algorithm : ``` def max_subarray_sum(nums): max_sum = current_sum = nums[0] for num in nums[1:]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return max_sum ``` Same problem. Cleaner logic. O(n) instead of brute force. Here's what I'm trying to say: going back to problems you’ve already solved might feel like you’re wasting time… but you’re not. It isn't. Sometimes it’s only when you revisit something with a fresh mind that you actually see better approaches you missed the first time. There’s almost always more than one way to solve a problem. Which one is "best"? That's a conversation for another day. What’s something you revisited and understood completely differently the second time? #Python #DSA #SoftwareEngineering #DeveloperLife #TechCanada

To view or add a comment, sign in

Explore content categories