I've been practicing a lot of algorithm problems, but I've noticed that when I get stuck, I sometimes read a solution, understand it briefly, and then move on. A few days later, I can remember the general shape of the answer but not why it works.
The Valid Parentheses problem made this especially obvious. I knew a stack was involved and could reproduce the code after seeing it, but I struggled to explain why a stack was the right data structure, what to do when it was empty, and why the worst-case space complexity is O(n).
I'm trying to slow down by writing my own explanation before comparing it with another walkthrough. For each problem, I now ask myself what the main pattern is, why the data structure fits, which edge case breaks a naive approach, and how I would explain the time and space complexity.
This takes longer, but the ideas seem to stick better. What review habits or problem-solving process help you learn the underlying patterns instead of just memorizing solutions?
5 Answers
Reading a solution is passive, so it’s easy to mistake recognition for understanding. If you do need help, use a small hint rather than the full implementation. Study the underlying technique separately, then close the reference and implement it yourself from memory. You can’t copy the experience gained from working through the problem.
Try to formulate the approach and write the explanation before writing any code. The important part is deciding what the solution should do; the code is mostly just implementing that plan. If the explanation changes while you code, update it so the final version reflects what you actually understand.
Treat the exercises as practice for problem-solving rather than a catalog of solutions. After solving one, revisit it later without looking at the code, explain the approach aloud or in writing, and solve a slightly different version if possible. An AI tutor can help turn the weak point into a new practice question, but you should still derive and code the answer yourself.
Give yourself a serious attempt before looking anything up—often an hour or more, depending on the problem. Re-read the constraints, identify the input and goal, question your assumptions, and first consider a brute-force solution. Then ask what information lets you make it more efficient. If you’re still stuck, take a break and return later instead of immediately consuming the answer.
A useful compromise is to ask for progressively stronger hints instead of opening the complete solution. Start with a question about the pattern, then the relevant data structure, and only ask for more if you’ve tried applying the hint. That preserves most of the productive struggle while preventing you from getting completely stuck.

That distinction between recognizing an answer and being able to rebuild it is exactly what I’ve been running into. Writing the explanation first should make that gap much easier to notice.