When Should I Look at the Solution to a Programming Exercise?

August 17, 2026 4 answers
Asked by ~8 postcards received
I tend to treat programming exercises like bosses in a Soulslike game: I keep trying until I finally beat the problem. The trouble is that some exercises can consume an hour or twoโ€”or even longerโ€”without me finding a solution. Is it reasonable to look at the answer after being stuck for that long, or should I instead look up individual functions and techniques related to the specific part that isn't working? Seeing a solution often gives me an immediate "ah, now I understand" reaction, but I'm unsure whether that feeling represents real learning. I also don't want to develop a habit of searching for the answer every time I get stuck. What's a good way to use solutions, hints, or other resources without undermining the purpose of the exercise?

Answers

Ricochet
Thereโ€™s no universal time limit, but spending hours on every exercise may not be the best use of practice time. If youโ€™ve made a genuine attempt and are no longer making progress, look at a small hint or the relevant technique, then solve a similar problem yourself. Repeated exposure to many exercises helps build intuition about which algorithms and data structures fit a problem, while getting permanently stuck on one exercise does not.
Reply to this answer
M4_torque
Looking at a solution isnโ€™t automatically harmful; copying it without understanding is the real problem. Try to study the approach, close the reference, and then recreate it yourself. A useful test is to attempt the same exercise again the next day without help. If you can explain and reproduce the solution, you probably learned something. If not, review the underlying idea and try again rather than simply copying more code.
Reply to this answer
PAPERBACKS ONLY
Use hints before revealing the entire answer. Ask what concept, data structure, or prerequisite you might be missing, or focus on the specific behavior that isnโ€™t working. Debugging with small experiments and print statements can also show you what the program is actually doing. The goal is to get enough guidance to make the next step yourself, not to have someone complete the exercise for you.

tidyDeskLamp: A helpful progression is to ask for a broad hint first, then a more specific hint, and only look at the full solution as a last resort. Afterward, rewrite the solution from memory and compare your approach with the reference.

Reply to this answer
arch_3span
Donโ€™t underestimate taking a break. After making a serious attempt, step away physicallyโ€”go for a walk, eat, or do something unrelated. Your mind may continue processing the problem in the background, and returning later can make the missing idea easier to see. A break is often more productive than spending several more frustrated hours staring at the same code.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions