Problem
Author & Editorialist : commandoak47
Tester : kingvarun
Difficulty :
Simple
PREREQUISITES :
Implementation
PROBLEM :
We are given an array of integers and we have to print one less than the maximum count of equal consecutive or alternate integers.
Solution :
Setter's Solution
#include<bits/stdc++.h>
using namespace std;
const int N = 200001;
void solve(){
int n;
cin>>n;
int a[n],temp[N];
for(int i=0;i<n;i++){
cin>>a[i];
temp[a[i]]=0;
}
int move=0;
for(int i=0;i<n;i++){
if(a[i-1]==a[i]){
temp[a[i]]++;
move=max(move,temp[a[i]]);
}
else if((i-2)>=0 && a[i-2]==a[i]){
temp[a[i]]++;
move=max(move,temp[a[i]]);
}
else
{
temp[a[i]]=0;
}
}
cout<<move<<"\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
HAPPY CODING