What to do at the time of Wrong Answer (WA)?
There is been always a case that a wrong answer gives too much pain rather than TLE (Time Limit Exceed), as in former you couldn’t ascertain about which test case it is failing but in later you can estimate that for which value of N (Total instruction), it would show TLE.
So What to do at that time?
- Read Question Carefully: At the first time, when you got WA(Wrong Answer) then always be sure that you have read each and every word and fully understand the question because most of the time we skipped that particular part which is the base of whole question.
- Check Input/Output formatting: Mostly Programmers usually forget to add new line or white space according to the requirement of question. So before submitting the solution to Online judge, try to run your program in online compilers like code.geeksforgeeks.org or ideone.
- Check Algorithm/Logic of program: Be sure that you are using correct logic that are covering all the test cases or not.
- Corner test cases Try to run your code on boundary test cases, if possible like 0, 1, 2 or N.
Avoid Silly Mistakes
- Initialize variable: Sometimes we forget to reinitialize variables, arrays after every test case T. For example-
- Initialize the value of count variable to 0.
- Setting all value of DP array to 0 or -1.
So input same or different test case atleast twice and check if correct output is obtained or not.
- Data type Overflow: Always keep the constraint given on value of N or other input in your mind, and make your program in the range of correct data type like int, long long in C/C++ or int, long in JAVA etc to avoid overflow.
- Modular Problem: In questions like Modular Arithmetic (answer % MOD),always ensure that answer is not getting a negative value, so try to use (answer + MOD) % MOD, that will cover all possibilities.
- The most important part is debugging: You can either use inbulit debugger of Codeblock, Ecllipse in C/C++ and JAVA respectively or you can print the variable after each and every line so that you can estimate that your program is running according to your requirement or not.
- Use Assertion: If you are going to write a plenty of lines in your code then using assert() is totally worth it. Click here to read more about how to use Assertion in Competitive programming.
- Look for Suggestions given: Although this should be the last step but you must look at the comments given below in which other programmers might have also facing the same problem and have given a hint on how to eradicate this issue.
Ultimately, always try to write a clean code with a small function that have well defined purpose.
This article is contributed by Shubham Bansal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.