Answers for "longest chain of same elemetns in an array"

1

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;
}
Posted by: Guest on April-27-2021

Code answers related to "longest chain of same elemetns in an array"

Browse Popular Code Answers by Language