Skip to content

Debugging Practices ​

Debugging is a core skill in competitive programming. Writing a correct algorithm is only half the work β€” you also need to make sure your code actually runs as expected, and be able to correct it if a mistake is found.


πŸ”‘ Key Advices ​

  • Always try the problem on paper first before coding.
  • Have a clear idea of your algorithm and used data structures. If possible, write an outline on paper before implementing (avoid blind coding).
  • Test on small and extremal cases that you can check manually.
  • Be careful with fast I/O and watch out for integer overflow.
  • Use cerr instead of cout for debugging (since graders usually ignore cerr).
  • A debugger is often more powerful than console output.
  • Learn to use assert to verify assumptions in your code.
  • Compare your solution with a bruteforce solution on small cases to locate discrepancies.
  • Train your debugging skills: don’t immediately read the editorial just because your mistake seems β€œdumb” β€” solving it yourself is part of the training.

πŸ“š Useful Resources ​


⚑ Debugging is not wasted time β€” it’s part of solving the problem.