Source Code
#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define LL long long
#define LD long double
#define pb push_back
#define F first
#define S second


const double PI=3.1415926535897932384626433;
const int KL=1e6;
const LL MOD=1e9+7;


using namespace std;
int a[1000010]={0} ;
int main ()
{
    int n ;
    sc(n) ;
    int  ans = 1;
    for (int i=0;i<n;i++)
    {
        int u; u+=500000 ;
        sc(u) ;
        if (a[u]==0)
        {
            a[u]=i+1;
        }
        else{ans= max(ans,(i+1)-a[u]+1 );}
    }
           cout << ans << "\n" ;

}
Copy
Good Segment alialsuleman
GNU G++17
2 ms
624 KB
Runtime Error