Problem in leetcode question. Unknown error in solution, please help

Have edited just a small thing in your code, you can see now it’s passing all test cases

Why is this happening btw?

Why is this necessary?

see when you initialize an array you give it a size , right ? We do it cause we have to operate on it’s ith index. Same goes for 1D vector. When you have to iterate on ith index then you have to initialize it with some size. But if you don’t want too initialize it’s size, then you can use push_back() for that. This happens only for 1D vector.

Understood. Thank you so much.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.