longest chain of same elemetns in an array code example
Example: longest chain of same elemetns in an array
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n;
cin>>n;
ll a[n];
for(ll i=0;i<n;++i){
cin>>a[i];
}
ll temp=1,ans=1;
for (ll i = 1; i < n; i++) {
if (a[i] >= a[i - 1]) {
++temp;
}
else {
ans = max(ans, temp);
temp = 1;
}
}
ans = max(ans, temp);
cout<<ans<<endl;
return 0;
}