import java.util.*;


public class Solution {

    public int maxLength (int[] arr) {
        // write code here
        if (arr == null || arr.length == 0) {
            return 0;
        }
        ArrayList<Integer> tmp = new ArrayList<>();
        int maxLen = 0;
        for (int i = 0; i < arr.length; i++) {
            int Len = 0;
            tmp = new ArrayList<>();
            for (int j = i; j < arr.length; j++) {
                if (tmp.size() == 0) {
                    tmp.add(arr[j]);
                    Len++;
                }else{
                    if (tmp.indexOf(arr[j]) != -1) {
                        i += tmp.indexOf(arr[j]);
                        break;
                    }
                    tmp.add(arr[j]);
                    Len++;
                }

                if (j == arr.length-1) {
                    return maxLen > Len ? maxLen : Len;
                }
            }
            maxLen = maxLen > Len ? maxLen : Len;
        }
        return maxLen;
    }
}