Source Code
#include <iostream>

using namespace std;

int n, a[1000000];
int a1[1000000];
int main(){
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);

	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{	
		int x;
		cin >> x;
		if (a[x] != 0)
		{
			a[x] = i - a[x]; 
		}else{
			a[x] = i;
			a1[x]++;
		}
	}
	

	int mx = 0;
	for (int i = 0; i < n; ++i)
	{	
		if (a1[i] > 1)
		{
			mx = max(mx, a[i]);
		}
	}

	cout << mx + 1;






	return 0;
}
Copy
Good Segment omarqwerty
GNU G++17
3 ms
464 KB
Wrong Answer