Is there any way to know for which testcase my code is failing?
Write a random test case generator. You have a correct solution available now else if it would not have been available write a brute force code and check at which cases your code is failing by matching the output of your code and the code which is for sure is correct.