Code is not running for two test cases

Hello guys , i’m unable to find the two test cases for which my code is not running.
problem link

Submission

Hey @prince_000, be clear that there are not just two, but the two of the cases failed on CC judge are two of a kind of failure in your code. I can see that your code is prone to errors like segmentation fault since you may access elements from freq with out of bounds indices. How? Because of your assumption of directly using values from frequency array as 0-based indexes which is only okay if the frequencies are in range 0 to freq.size()-1, correct? Whereas there’s no such constraint mentioned on the problem statement.
Due to this (from line 17 onwards in your submission link), even an input like:

4
4 5 6 7

will cause a segmentation fault in your program, thus giving the runtime error that you see in your verdict. Rest looks good with your logic on the remaining cases :slight_smile:

1 Like

Thx @harshit_0 for your wonderful explanation. I understand my mistakes.

1 Like