Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
int n;
while(t--){
cin>>n;
int arr[n];
for(int i = 0; i < n; i++){
cin>>arr[i];
}
for(int i = 0; i < n; i++){
if(i == 0 && arr[i] != arr[i+1] && arr[i] != arr[i+2] ){
cout<<(i+1)<<endl;
break;
}
if(i == 0 && arr[i] != arr[i+1] && arr[i] == arr[i+2] ){
continue;
}
if(i == n-1){
cout<<(i+1)<<endl;
break;
}
if(arr[i] != arr[i+1] && arr[i] != arr[i-1]){
cout<<(i+1)<<endl;
break;
}
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
4
4
11 13 11 11
5
1 4 4 4 4
10
3 3 3 3 10 3 3 3 3 3
3
20 20 10
4
11 13 11 11
5
1 4 4 4 4
10
3 3 3 3 10 3 3 3 3 3
3
20 20 10
Output
2
1
5
3
1
5
3
Demonstration
Codeforcess solution 1512-A A. Spy Detected! ,C++, Java, Js and Python,1512-A,Codeforcess solution