Open In App

What to do at the time of Wrong Answer (WA)?

Last Updated : 12 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.
  • 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. 
     

Debugging 

  • The most important part is debugging: You can either use inbuilt debugger of Codeblock, Eclipse 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. 

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads