How to Test the Solution

This is the thing I want that how all of you test Your solution correctness because it is quite frustrating sometimes when not able to get a clue that what is wrong with the code,what is the reason behind it.

Some Ways:-
1>Seeing constraints and all.
2>Writing brute force approach ( any particular way to match this brute solution with the my solution ,any type of tools used, I am just asking the way to be done)

I want to know that how to test my solution,So please post your ways of testing the correctness.
This happens often in greedy problems and many more.

Hello, I think generally Wrong Answers are due to :

  1. Wrong Logic.

  2. Neglecting boundary/corner cases.

  3. Integer Overflows.


1) Wrong Logic :In this case your idea/ logic is wrong.But the sample test cases may work fine with the logic.So If this is the case just you can notice it by trying small random test cases using pen and paper.

2)Neglecting boundary/Corner cases : In this case you need to think more. i.e ;You need to cross check your approach more than once so that you can find bug in your program.And also test your program using boundary values,In this case what I will do is that just generate random small inputs and check my program several times(may be 20-30 times).So that there is a possibility of knowing the corner case/ getting the bug fixed.

3)Integer Overflows: This is the easy case you can handle.You can just test the program by using large inputs(limited to constraints).

1 Like