How long should I struggle with a DSA problem before checking the solution?
Asked by
MellowPine42
I'm practicing data structures and algorithms, especially sliding-window problems, but I sometimes spend two or three hours trying to find a solution. How can I tell whether I'm making useful progress or just going in circles? When should I use a hint or read the solution, and how can I make sure I actually learn from it instead of simply copying the answer?
Answers
Looking at a solution can be part of learning, but donโt stop at reading it. Study the key idea, identify the clue that reveals the pattern, close the explanation, and recreate the algorithm yourself. Itโs also useful to revisit the problem later and solve it again without assistance. Over time, repeated exposure to patterns such as sliding windows will make similar problems much faster.
Reply to this answer
If you have a deadline, look up the solution sooner so you donโt lose the entire study session. For pure practice, spend some time exploring first, then use the smallest amount of help neededโa hint, a diagram, or the core idea. Immediately copying a complete solution may produce working code, but it usually teaches less than reconstructing it yourself.
Reply to this answer
A practical limit is around 20โ30 minutes if youโre completely stuck, or up to 30โ45 minutes if youโre still making meaningful progress. Start with a hint or the general pattern rather than immediately reading the full solution. Then put it away and implement the approach yourself from memory. The point is to learn how to recognize patterns, not to prove that you can independently invent every known algorithm.
Reply to this answer
Pay attention to whether youโre actually eliminating possibilities, testing ideas, or improving your understanding. If youโre just staring at the same code, repeating failed attempts, or feeling burned out, take a break and come back with fresh eyes. If you still have no direction after that, checking the solution is completely reasonableโjust focus on understanding the logic and how you could recognize the same approach in a future problem.
Reply to this answer
Add your answer
Answers are reviewed before publication.
MellowPine42: That makes sense. Iโll try to distinguish between slow progress and simply going in circles before looking for help.