• + 0 comments
    import java.util.*;
    public class test {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            Deque<Integer> deque = new ArrayDeque<>();
            int n = in.nextInt();
            int m = in.nextInt();
            ArrayList<Integer> sizeArr = new ArrayList<>();
    
            for (int i = 0; i < n; i++) {
                int num = in.nextInt();
                deque.add(num);
            }
            //change to list so that it can be easily sublisted
            List<Integer> list = new ArrayList<Integer>(deque);
    
            //sub-queue loop
            for (int i = 0; i <= n-m; i++) {    //farthest index to start subqueue will be "n-m" (to n)
                HashSet<Integer> hs = new HashSet<>(list.subList(i, i+m));
                sizeArr.add(hs.size());
            }
            System.out.println(Collections.max(sizeArr));
        }
    }