import java.util.*;


public class Solution {
    /**
     * 
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public int maxLength (int[] arr) {
        // write code here
        if (arr == null || arr.length < 1) {
            return 0;
        }
        Map<Integer, Integer> map = new HashMap<>();
        int j = 0;
        int max = 0;
        for (int i = 0; i < arr.length; i++) {
            if (map.containsKey(arr[i])) {
                j = Math.max(j, map.get(arr[i]) + 1);
            }
            map.put(arr[i], i);
            max = Math.max(i - j + 1, max);
        }
        return max;
    }
}