Please read the new rule regarding the restriction on the use of AI tools. ×

PathToMaster's blog

By PathToMaster, history, 5 hours ago, In English

Hello, Codeforces. I know you all have been there: coding a solution that gives a wrong answer and then being many minutes, or even hours, trying to find the bug in the code, becoming frustrated because you feel you are wasting time you could be using solving other problems. Have you any tips or a strategy for successfully debugging incorrect solutions?

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

write a brute force solution which gives correct answer and test your current solution by generation random numbers using generator and find the test case where your solution result in wrong answer

»
3 hours ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

I'm still a specialist and my level isn't that high.
But I'm a software engineer. So my strategy is engineer-like.

1 . Write readable code, which makes logic clear and easier to debug

  • use lambda functions for logic repeated more than twice.
  • use variables to clarify the meaning of calculation results
  • give variables short but descriptive names

2 . Print debugging -> cpp-dump