In your coding Questions, the “Wrong Answer” status of your test cases implies that your program or coding logic is unable to produce the exact expected output for the test cases due to various reasons.
Some primary causes and possible resolutions are explained below:
|Mismatch of Input and Output Values
Test cases fail when the input passed by your code may not be in the exact format as expected by the test case. Also, when the output returned by your code is not the exact expected output format, you will see a “Wrong Answer” status.
- When you write your own programs, ensure that you've understood the expected input and output values. If available, download the sample input and output values for reference.
- If predefined functions are provided, check the defined functions or methods to understand the expected input format and output format. Change your code accordingly.
- If your output value is correct, but its expected format is different, write the output value in the exact expected format.
A mismatch between the output formats
|Question Comprehension -handling edge cases
If some of your Test cases have passed, but you see a "Wrong Answer" status for others, it may imply that your coding logic is unable to handle the corner cases expected from the solution. For example, test cases which validate boundary values may fail if you've not written the logic to check for boundary values.
- Your understanding of the question and the expected solution may differ. A problem can have multiple solutions, but your logical solution must be based on the given constraints in the Question.
- Debug your code and validate different corner cases with custom inputs.
- Ensure that you've understood the expected solution and the various constraints explained in the problem statement. Modify your program or coding logic accordingly.
- Ensure that you read the problem statement, constraints, expected solution, and the sample cases thoroughly to analyze your logic.
An incorrect output from the solution
|Issues with code formatting or package guidelines
Check for other issues in your code such as:
- Extra/missing whitespaces
- Debug output values printed in the "Your Output" area. After debugging, you must remove or comment your debug print statements in code.
- Incorrect Class or Package names - (For Java, Scala and Clojure projects ensure that the correct naming guidelines are followed for Classes and Packages. This is required for your code to run and execute the test cases).
Debug output is compared with the expected output
It is recommended that you verify the above-mentioned causes and also debug your solution to identify the issues. Refer to the following topics for information about debugging your code: