This is my submission for TOWIN problem. Can any body tell what’s the problem with this approach?
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 which would be garbage value.
For test case
If I print p2, I got 0 as answer
What about multiple testcases?
5 4 3 2 1
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.
Got it!!! Thanks