Exact same solution WA in java while AC in C++

Contest : Code Invicta
Problem : Match The Rhyme(CINVIT01)
I am getting WA in java solution [CodeChef: Practical coding for everyone] while AC in exact same solution [CodeChef: Practical coding for everyone] .
I can assure that it is not because of performance difference between java and C++ as it is explicitly showing WA and not TLE (and also n is very small (less than 30) ).
Can someone tell what’s the problem.

I checked your Java Code. You are using try-catch block to avoid Runtime error. If an exception is raised, your program is terminated instantly. I commented the try-catch block and the modified solution is resulting in RTE.

1 Like

Oh I didn’t knew that. I was using try and catch in every code. How to prevent it from throwing that exception.

1 Like