the code seems pretty fine,i didnt find any test case where i am getting nzec error in cmd but here it shows nzec error??

here is the question

here is my solution

And additionally,can anyone inform me if i can check all the cases of which my code is being tried on, with details of which test case showed which error?(of the practice sets)


I’m not that familiar with java but i think you code will get NZEC error whenever string size is 1. string size is 1 and you are accessing value 1 which doesn’t exist.

from your code.

if(sb.charAt(0)==‘m’ && sb.charAt(1)==‘s’)


Hope this helps!

well,try the following test case:




you ought to check for corner case where |s| == 1.

further, in your first loop, you ought to change to condition from ( i< l ) to (i < l-1 ) to avoid StringIndexOutOfBoundsException.

You may refer my Solution.

Please Upvote if u found this helpful. :slight_smile:

1 Like

No, you can’t see the test cases that are being used. You can see them on Codeforces and HackerRank(as far as I know), but not in codechef.