Uncle Johny

https://www.codechef.com/viewsolution/18918873
//
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int a[100];
int b[100];
for(int i=1;i<=n;i++){

	cin>>a[i];
}

int d;//initial johnny position
cin>>d;
for(int i=1;i<=n;i++){
	b[i]=a[i];
}

	sort(a, a+n+1);
int m=b[d];

int count=0;
for(int j=0;j<n;j++){
if(a[j]!=m){
count++;
}
else{
break;
}
}

cout<<count+1<<endl;
}
return 0;

}

Here’s my optimized AC Solution:

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