Why is my code getting runtime error even when it passes the testcases?

What’s wrong with this solution? It outputs correct for the given test cases, but when I click submit it says runtime error. What’s the issue?

Solution: CodeChef: Practical coding for everyone

You are not checking if it’s a W valid string to begin with. Your code will get Runtime Error (out of bounds) in cases like:

a#a#a

Note that statement nor constraints guarantee the presence of at least 3 “#”, and your code needs 3 to work.

1 Like

Thanks a lot, it fixed the issue

1 Like