question
https://hack.codingblocks.com/contests/c/512/369
my code
https://ide.codingblocks.com/s/36406
Why wont my code work for index n-1
your order of if checks is wrong put them like this
if(a[i]==key){
j=i;
}
if(i==n-1){
cout<<j;
return ;
}