Source Code
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n; scanf("%d", &n);
    int array[n];
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &array[i]);
    }
    int max = 0, temp;
    for (int i = 0; i < n; ++i)
    {
        for (int j = i; j < n; ++j)
        {
            if (array[i] == array[j])
                temp = j - i;
            if (temp > max)
                max = temp;
        }
    }
    printf("%d\n", max+1);
    return 0;
}
Copy
Good Segment M_20x
GNU G++17
2004 ms
1.6 MB
Time Limit Exceeded