Needed help in TOWIN

This is my submission for TOWIN problem. Can any body tell what’s the problem with this approach?

https://www.codechef.com/viewsolution/36703222

You are not handling the case when n=1 or n=2 !!!

I have already handled that thing in line 17, 18

In line 18, when n=1 ,you are accessing arr[2] which would be garbage value.

2 Likes

For test case
1
1
100000

If I print p2, I got 0 as answer

What about multiple testcases?

2
5
5 4 3 2 1
1
2

Here, for second test case you will be accessing values from previous test case.
Either check if the index you are accessing in within bounds or clear the array everytime.

3 Likes

Thank you!!!

1 Like

Got it!!! Thanks

1 Like