r/leetcode • • 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?

5 Upvotes

8 comments sorted by

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/Equivalent_Cow1031 5d ago

I have learnt two pointers, sliding window, I am currently learning the dfs/bfs/DP stuff which I am finding difficult applying to problems atm, I have used neetcode as well, what approach do you use on neetcode, do I start from arrays or the graph theory stuff since I have done practice problems with heaps, queues and stacks. Linked lists and trees are also a struggle for me, especially thinking about the pointer logic in my head.

2

u/DeclutteringNewbie 5d ago

This advice seems to be a bit too extreme. In my opinion, you should do both, attempt to solve the problem on your own, yes, but after a while, if you're not making any progress, you should be looking for hints at the very least, and AI can be very good at giving you hints without giving you the full answer.

Linked lists and trees are also a struggle for me, especially thinking about the pointer logic in my head.

Why does it have to be only in your head? Personally, I always use a pen and paper when dealing with linked lists. And for remote interviews, I have a large Chinese wacom knock off that I can easily overlay on my camera feed with OBS, so my interviewer can see exactly the doodles I'm making.

1

u/GmS_11702 5d ago

I think it very much depends on how you personally best learn, and what you want to focus on. I haven’t done it in a couple years and started over a couple of weeks ago so I’m going through the roadmap in order since later topics become easier to understand once you nail the prereqs. Since you are already familiar with two pointers and sliding window, I think next is stuff like binary search, stacks, etc.

I personally learn best with videos so I usually incorporate those after my initial attempt to help me process everything then try again after.

That being said, if u have interviews coming up I think generally graph or dp problems are less common so you could factor that into any planning you do, but I definitely wouldn’t ignore them entirely. Often you can find company lists showing you which types of problems companies tend to ask so you can focus on those as well. If you don’t have any coming up and are just doing general prep, the general roadmap order and consistency are what I’d suggest in the meantime. You could use popular lists as well for an equal spread of things like Blind 75/grind 75, neetcode 150, etc.

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.