I've just started learning Data Structures and Algorithms a few weeks ago, and I have a burning question: Is it common for folks to come up with the most optimal solutions to problems all by themselves? Take the Maximum Subarray Sum problem, for instance—I can barely grasp the brute force method. Is it realistic to expect that someone would be able to derive the Kadane Algorithm on their first attempt? For me, it feels like memorizing solutions is the only way forward.
5 Answers
Honestly, most people don't figure out Kadane's algorithm on their first go—that's completely normal! A lot of even seasoned developers look up optimal solutions for problems they encounter for the first time. The key is to understand how the algorithm works, like how Kadane's tracks the max amount so far and resets when the sum goes negative. Memorization is fine at first, but really try to grasp the logic. It’ll help you recognize similar patterns down the line.
If you're looking for a good resource to learn algorithms, check out this book! It comes with accompanying lecture videos, which can be really helpful: https://www.amazon.com/Algorithms-4th-Robert-Sedgewick/dp/032157351X.
The goal isn't to independently develop every known algorithm. Instead, you should recognize when an algorithm might be applicable. Learning how they work gives you the chance to modify them for specific situations, which can lead to better performance.
First off, it seems like you're diving into LeetCode before mastering DSA basics. DSA is foundational, while LeetCode is more about applying those concepts. Most people don’t just whip up optimal solutions on their first try; it takes practice and a solid understanding of mathematics and DSA principles.
I started with basic programming too before venturing into DSA. It's fine to review basics to get comfortable with syntax, but make sure you're focusing on the core DSA concepts afterwards.
Most of the time, people don’t come up with those complex algorithms, especially not on the first try! If these problems were easy to derive, they wouldn’t be named after the researchers who first discovered them. It’s more about learning the algorithms and knowing when to apply them rather than generating them from scratch.

Exactly! Many folks only stumble upon O(n) algorithms after they know they exist. That’s part of learning—DSA exposes you to key approaches, making it easier to spot solutions without having to memorize everything.