iLoveIOI's blog

By iLoveIOI, history, 2 years ago, In English

Can someone please recommend a way to debug a code that passes the sample test cases but fails the main tests. Thanks

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

2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Lol. Lmao. Your question is too generic. There is no "good" way for debugging code. If you just want examples of what you can do, I have listed a few below:

  1. try the built-in debugger in any IDE (I recommend Jetbrains IDEs).
  2. generate some random test cases and write brute force to get correct answer.
  3. logically reason about your algorithm.
  4. test different parts of your code in isolation.
  5. test your code on extreme cases (e.g. sorted input, all same values)