Is it necessary to handle invalid test cases for the problem to be correct. I mean the test cases for checking the solution, does it also contains invalid inputs.
No it do not contain invalid input . Inputs are always in the range mentioned in the constraints .