What’s wrong in my solution to MARRAYS in October long challenge OCT17. I have seen many AC solutions did the same thing. Though, I might be overlooking something.


You are getting an NZEC because n may be 1 but you are accessing arr[n-2] which is out of bounds. And you are likely getting a TLE because you are using push_back() to append whole vectors. This actually copies the vector into a new one which is not required and wastes some time.

However this is not the intended solution and such solutions would not pass with strong test cases. You can check the editorial for a better approach. You can also see my explanation here if it helps.

1 Like