import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public int maxLength (int[] arr) {
        // write code here
        int n = arr.length;
        if (n == 0) return 0;
        int res = 0;
        HashSet<Integer> set = new HashSet<>();
        for (int j = 0, i = 0; j < n; j++) {
            while (set.contains(arr[j])) {
                set.remove(arr[i]);
                i++;
            }
            set.add(arr[j]);
            res = Math.max(res, set.size());
        }

        return res;
    }
}