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: import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
	public static void main (String[] args) {
                      // Your code here
		Scanner sc = new Scanner(System.in);
		int arrSize = sc.nextInt();

		long arr[] = new long[arrSize];
		for(int i = 0; i < arrSize; i++)
			arr[i] = sc.nextLong(); 
		
		System.out.println(maxDist(arr, arrSize));
	}

	static int maxDist(long arr[], int arrSize)
	{
		int ans = 0;
		HashMap<Long, Integer> hMap = new HashMap<>();
		for(int i = 0; i < arrSize; i++)
		{
			if(hMap.containsKey(arr[i]) == true)
				ans = Math.max(ans, i-hMap.get(arr[i]));
			else
				hMap.put(arr[i], i);	
		}

		return ans;
	} 
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?