Today while solving a problem I came up with this solution . which passes the first test case but gives wrong answer on the 2nd case and the problem is Idk what the test is since its not visible . I have tried generating random test cases by myself and also using chatgpt to understand which case it could be failing on but no luck . So i wanted to ask how do you guys debug it . this is the first time I have encountered this issue (i am new :P) . Any help on the problem would also be appreciated :) . thanks









link to blog
You don't. Looking at failed test cases and then debugging the problem is like taking hints, which is not forbidden, but it hinders your thinking ability and you'll develop a habit of it. You're supposed to figure out the failed test cases on your own.
No, it's perfectly fine. Especially during contests (generate a thousand cases, one of them will be wrong) is much more reliable than coming up with them on your own.
And how do you create them and check wether they are correct?
Brute force probably
To create: write a dumb generator that can plausibly generate any small test case. It's not important that it has uniform distribution or anything.
To check: usually you can write a stupid brute force solution. It might run in exponential time but that should be fine: most bugs can be caught with like $$$n = 8$$$.
Sometimes if there are multiple answers, you can instead write a small checker function in your code and add a simple
assert.Oh ok, thanks :)
Stress test.
I have created a sample that will cause your program to fail.
The most negative-looking positive comment I saw.
No Doubt ! you can try various things like stress testing, generating edge cases, etc. But if you want to view the test which is failing you can use the below approach.
Although most of the CF community members know this trick.
Few Days back I was solving the problem 1978C - Manhattan Permutations. On first submission I got WA on test 2 266054646, so wrote added this extra code to print the input on terminal 266058305.
if(_ == 305): print(str(n) + "000" + str(k))Hence I got the failed test case, and then I corrected it 266059198.
Also if you are getting a WA there are a high chances that it might come in test 2, because 3 and further are mostly designed to check if the code gives TLE.
Furthermore if an array type input is giving the wrong answer, use the same technique which I mentioned above :
str(a[0]) + "0000" + str(a[1]) + "0000" + ...
This technique mostly works because on test 2 mostly the length of array and array values are small and we can easily seperate them by adding some 4-5 zeros bewtween them.
Hope this helps !!!
Think about edge cases as well