Problem in one test case

@akash_281
This is the updated code.


You were accessing index n but elements lie between indexes 0 to (n - 1).
Thus if you wish to proceed via 1 based indexing, you should build an array of size of (n + 1) and store elements from indexes 1 to n. But you will have to return (n - 1) because the answer is following 0 based indexing. It would be less cumbersome if you proceed via 0 based indexing.

If my answer was able to answer your query, please mark the doubt as resolved.

1 Like

hey @LP18Aug0068
Can you explain with a testcase?

@akash_281
suppose the elements are 1 2 3 4 5. You placed them in indexes from 0 to (n - 1). But you accessed an element on index n which is non existent. This might have been the reason for the error.