Mike Mossey tutoring logo

USACO tutoring with Mike Mossey

Your USACO journey starts with a great teacher

Debugging tips

What to do when your program fails some test cases

First, read the problem statement carefully.

I recommend going through the problem statement word by word and checking your understanding of the problem against each word. Sometimes you’ll notice some part of the problem you forgot to implement. It’s really important to go through word by word. This is the best way to find things that you missed. Some of us are good at reading fast or skimming. This is not what you want to do.

Second, read your code carefully

As with reading the problem, I recommend reading your code word by word, symbol by symbol. Ask yourself for every symbol, “Does this fit my understanding of the problem?”

Third, add debugging print statements or throw the code into the debugger

It’s usually easier to add some debugging print statements than it is to use the debugger. You may not have a debugger available in your IDE. A common situation is that you’re not sure if your execution is reaching a part of the code. You can add a print statement there, like System.out.println(“here”);, and you’ll see right away if that part of the code is executing.

You might also like to print certain values. It’s a art form to decide which values to print. You must figure out which values will give you the most information. This is something I work with my students on doing well.