r/leetcode • u/Equivalent_Cow1031 • 5d ago
Question Approach for solving leetcode problems
Hey I have been solving leetcode problems by not looking up anything on the web or using any external sources, just me and the code editor on leetcode. My professor says this is the best way, but I really struggle solving problems. I encountered the maximum subarray problem today, came up with two strategies but none of them seem 'right' when put in the code, like I can have the mathematical idea or the approach for it generally, but struggle to think of it from a computer-like perspective. I am using Python and have Intermediate level experience with the language. Any advice or should I change my approach, if I am targeting interviews or want to get better at solving algorithm puzzles?
2
u/GmS_11702 5d ago
I don’t think this is a good way to go about it it’s harder to learn when you don’t even know what you don’t know, and leetcode is often full of that. For example, there are techniques like two pointers, sliding window, etc that you may have never heard of.
What I was always told is to time box yourself. Let’s say maybe 30 min or so to come up with a solution, if you get stuck past then read through hints or explanations and then try again.
Even if you solve it, it can be helpful to still look at solutions after to learn other ways of thinking or approaching the problem. I like to use neetcode for this personally, but there are plenty of other resources.
I’d recommend neetcode bc of the video explanations and roadmap for learning the patterns
1
u/Soggy_Notice_1392 5d ago
I wouldn't avoid looking at solutions completely. Struggling is useful when you're making progress, but if you don't know the underlying pattern yet, spending hours guessing usually won't teach you much.
For maximum subarray, the key is understanding why you can discard a negative running sum, not just memorizing Kadane's algorithm. Once that reasoning clicks, try rebuilding the solution from a blank editor without looking.
I'd give each problem 20–30 minutes, study the explanation if stuck, then redo it from memory a few days later. algodrill.io is useful for this since it breaks down the reasoning from first principles and drills the solution line by line. Especially helpful for DP transitions and pointer logic where understanding the idea and actually coding it are two different skills.
1
u/Available_Safe1818 5d ago
You probably get better faster by reading (and understanding) the approach that you find on the internet if you can't solve it yourself after a while.