For this Question: Given an array with repeated elements, the task is to find the maximum distance between two occurrences of an element.

Note:- It is guaranteed that atleast one number is repeated.The first line of the input contains an integer N denoting the number of elements in the array, the next line contains N space separated integers.

Constraints:
1 <= N <= 100000
1 <= Arr[i] <= 10^9For each test case in new line print the Maximum distance between two occurrences of an elementSample Input
6
1 1 2 2 2 1

Sample Output
5

Explanation:-
The index of two occurrences are:- (1, 2), (1, 6), (2, 6), (3, 4), (3, 5), (4, 5)
it can be seen that the maximum distance is between (1, 6) i. e. 5

Sample Input
5
1 1 1 1 1

Sample Output
4, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int main()
{
   
 int n;
 cin>>n;
 long a[n];
 unordered_map<long,int> m;
 int ans=0;
 for(int i=0;i<n;i++){
    cin>>a[i];
    if(m.find(a[i])!=m.end()){ans=max(ans,i-m[a[i]]);}
    else{
        m[a[i]]=i;
    }
 }
 cout<<ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?