You are viewing a single comment's thread. Return to all comments →
simplest logic
Scanner in = new Scanner(System.in); Deque<Integer> deque = new ArrayDeque<>(); int n = in.nextInt(); int m = in.nextInt(); int max = 0; for (int i = 0; i < n; i++) { int num = in.nextInt(); deque.add(num); if(deque.size()==m){ int size = new HashSet<Integer>(deque).size(); if(max<size) max = size; deque.removeFirst(); } } in.close(); System.out.println(max);
Seems like cookies are disabled on this browser, please enable them to open this website
Java Dequeue
You are viewing a single comment's thread. Return to all comments →
simplest logic