I tend to treat programming exercises like bosses in a difficult game: I keep trying until I finally beat them. However, some problems can take hours, and I still may not find a solution. Is it reasonable to check the answer after spending an hour or two stuck, or is it better to look up smaller hints, relevant functions, or prerequisites instead?
Seeing a solution often gives me an immediate "oh, that makes sense" feeling, but I'm unsure whether that leads to real learning—especially if I start checking the answer every time I get stuck. What's a good way to use solutions without simply copying them?
4 Answers
Before checking the answer, take a real break. A walk, meal, or night of sleep can give your brain time to work on the problem in the background. When you return, try again briefly. If you’re still stuck, use a hint or the solution as a learning tool rather than treating it as a failure.
Use hints before reading the entire answer. Ask what concept, data structure, or prerequisite you might be missing, or focus on one specific step. Debugging with small experiments and print statements can also reveal that your code isn’t behaving the way you assumed. The goal is to get just enough help to continue thinking, not to have the whole exercise completed for you.
You don’t have to spend one or two hours on every exercise. Part of learning is building intuition about which techniques apply, and that comes from seeing many examples. If you’re making no progress after a reasonable attempt, read the solution, explain each step in your own words, and then write it again from memory. Spending all your time stuck can be less useful than studying the answer and moving on to another problem.
Looking at a solution isn’t automatically bad; copying it without understanding is the problem. Try to understand the approach, close the solution, and then recreate it yourself. A useful test is to attempt the same problem again the next day without help. If you can reproduce the idea and code reasonably well, you probably learned something. If not, study the solution more actively and practice a similar problem.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically