What to do when solution’s idea is right, but code fails on large test. How to find the bug?
# | User | Rating |
---|---|---|
1 | Benq | 3783 |
2 | jiangly | 3772 |
3 | tourist | 3706 |
4 | maroonrk | 3609 |
5 | Um_nik | 3591 |
6 | fantasy | 3526 |
7 | ko_osaga | 3500 |
8 | inaFSTream | 3477 |
9 | cnnfls_csy | 3427 |
10 | zh0ukangyang | 3423 |
# | User | Contrib. |
---|---|---|
1 | Um_nik | 185 |
2 | awoo | 182 |
3 | nor | 172 |
4 | -is-this-fft- | 170 |
5 | adamant | 169 |
6 | maroonrk | 165 |
7 | antontrygubO_o | 160 |
8 | SecondThread | 158 |
9 | dario2994 | 151 |
9 | kostka | 151 |
What to do when solution’s idea is right, but code fails on large test. How to find the bug?
Name |
---|
You should consider your previous experience with bugs and how to fix them. For example:
I also recommend using assert function as possible as you can so you know if your code works properly or not. In this case, when I get the wrong answer verdict I am almost sure that my solution is not correct and the mistake is not about my bad implementation.
When you can't figure out where the bug is you can do stress testing on your solution, if you have enough time, to get a test case that makes your solution fail.
Do a stress test and try to find a smaller test case which fails.
Top-to-down approach
Start from the top from where the program starts and comment the rest of cold below. Do a test on it debug it and go on to the next part. uncomment some parts and test them and so on..
Your Free Waifu
also check if vectors/other data structures has elements left before trying to query, i RTE'd 5 times on a problem once because i forgot to check if the vector is empty or not before getting the value of v.back()