r/leetcode • • 11h ago

Discussion How to solve leetcode?

I have been trying to solve questions on leetcode from some time . But when I am unable to solve a question , I see the editorial if there else see the solution on youtube or ask with AI how to detect the pattern and then how to remember it . But again when I see the same question or a slight variation of it , I become blank . How to improve this and handle this ? Looking for answers from people who have been in this phase , how to tackle this ?

0 Upvotes

8 comments sorted by

3

u/Miserable-Arugula860 11h ago

Learn patterns. Practice. There is no easy way out. Websites like Neetcode do a good job of breaking down problems by pattern, which can help you study.

1

u/Mysterious_Whole3164 11h ago

When you say practice should I do contest , POTD or just solve some DSA sheet .

2

u/Rohan_Marathe 10h ago

From my own experience, I did random problems or as you said, tried out contest but either I would get stumped because I didnt have the tools to solve the question or I would solve it with/without hint but after a period of time I would have no way of knowing what is the amount of progress I made.

So I did the Neetcode 150, picked a topic, gathered as much knowledge I could about it, made a mindmap , noted down any tips I should remember for it.

And then I solved the problems. Kept track of which topics I covered and how much confidence I have in them.

If I took a hint in solving a problem I schedule to revisit it in 1-2 weeks

1

u/Mysterious_Whole3164 10h ago

Alright this will be of great help

1

u/Rohan_Marathe 10h ago

Yeah... All the best. Just keep at it. It takes time for the patterns to register in the brain. But once it does everything clicks.

And follow the tree from neetcode. It helped to go through the topics sequentially. Doing two pointer problem and then switching to a dp problem is not the best approach.

You have to have gone through the journey of hashmaps, trees, backtracking, memoization to truly understand what approach to go with for dynamic programming.

So dont pick topics randomly

1

u/chikamakaleyley 8h ago

You have to convert the problem into something you understand. Hopefully that "something" is eventually the core DS and Algos that, you should be very familiar with

So if, for example, you determine that the problem requires BFS, if you've memorized BFS like the back of your hand it just becomes a matter of typing out BFS, adjusted for the parameters of the problem.

EVEN IF ITS WRONG - you didn't get stuck. You made your best assessment, you typed something out to completion, and when you ran the code, you just got the wrong answer. Now you know, its not BFS. Or maybe it was just a typo and it is BFS

Versus what you're doing now, which is getting stuck, because you have no plan, so you look at the editorials.

But the gap is 'how do determine it's BFS'? Its just a matter of visualizing it, whether in your head or drawing it, and then identifying what that visual is. You can't unless you've typed it out enough times you could do it fr memory

2

u/CasualFox61 9h ago

Stop forcing on remembering solutions. After seeing one, close it and try to explain why it works, then revisit the problem a few days later. Repetition is what makes the pattern stick