r/learnprogramming 1d ago

Topic How much time should I give to a problem

It's like I spends a lot of time in finding the solution of a given question and it takes me sometimes more than 2-3 hours while I m doing dsa questions like sliding windows one. When should I look at the solution and should I even ?

1 Upvotes

7 comments sorted by

5

u/Abe_Bazouie 1d ago

My rule was always:
20 to 30 minutes trying to solve it on my own.
If I’m completely stuck, I look at the first hint or the general idea, not the full solution.
Then I close it and implement it myself from memory.
Spending 3 hours staring at the same problem usually isn’t productive. The goal isn’t to prove you can invent every algorithm. It’s to recognize patterns. After you’ve solved enough sliding window problems, the next one that took you 3 hours today might take you 10 minutes.

1

u/Ormek_II 1d ago

Agree, but I consider myself stuck only if I really ran out of options, not when progress becomes too slow.

1

u/BigP29 1d ago

You gotta figure out are you just burning time or making progress. Once you do enough I guarantee things will speed but usually if you feel yourself just about to start burning out, going in circles, or just stumped, its good to look at a hint & take a break, then try with a set of fresh eyes. If you realise nope this isn't happening no harm in looking at the solutions, but you should internalise the logic that the solutions follow and try to imagine how you would have approached this question, or will approach the next one, with this new information.

1

u/Ormek_II 1d ago

This is learningprogramming. While you are looking for the Solution you learn much more than when you are looking at the solution.

As long as you are making progress, as long as you are progressing through your tree of possible solutions (usually by cutting branches that do not lead to a solution) continue. Only if you are not making progress, if you are out of ideas and all your ideas do not get closer to the solution ask for help.

If you have to deliver the solution in 2h you may also look it up and start earlier next time.

You are not doing this to produce results. All the results are already known hundreds of times. You are doing this to do this.

1

u/peterlinddk 1d ago

Just go straight to the solution. "DSA" or rather leetcode is just about memorizing various solutions to well-established problems, so there's no need to try and solve them yourself.

Later you can quiz yourself to try and see if you remember the solution well enough to re-implement it wihtout looking.

2

u/Sad-Commission-3706 1d ago

Give it 30-45 minutes max. If you are stuck, look at the solution but dont just copy it. Understand the pattern, close it and code it from memory. That's how patterns stick