Solution gives RE with vector but passes test cases with array

The below code gives runtime error (SIGABRT) while using vector, but if I make the count variable an array without changing anything else, it passes the test cases. CodeChef: Practical coding for everyone

I looked up what causes SIGABRT and I found it mostly happens while using assert statements or accessing an invalid memory location. I don’t think either is happening with my code. Please help me find the source of error.


PS : I figured out my mistake, I am indeed accessing indices out of the bounds of the vector. Precisely, I am accessing count[-1]. The thing is arrays show undefined behaviour when accessing indices out of bounds. See c++ - Accessing an array out of bounds gives no error, why? - Stack Overflow for more information. Hence, my code worked when switching count to an array. I am leaving this post as it is partly for self reference and I also believe many beginners like me are unaware of this fact. Maybe this will save some from a RE during a contest.