WA - INCPR04

I am getting WA in this problem - INCPR04
My solution - https://www.codechef.com/viewsolution/29940014

Passes test cases, but why WA? Please help.

Bro it’s failing this test case
1
4 2
4 3 2 1

You are comparing
if ( A[i] == K )

but , According to question you have to find the index means you have to do
if ( i == K )

and it will be accepted :smile:

Two changes, Add a line

k=a[k-1];

and put

break;

inside the if condition.

Thanks.

1 Like

Yo bro you too study in grade 9 :smile: