We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hi Any idea, what am I doing wrong here,
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();
boolean debug = true;
int unique = 0;
for (int i = 0; i < n && unique < m ; i++) {
int num = in.nextInt();
while(deque.contains(num) && deque.isEmpty() == false) {
deque.pollFirst();
}
deque.addLast(num);
unique = Math.max(unique, deque.size());
if(debug) {
System.out.println(num);
System.out.println(deque);
System.out.println(unique);
}
}
System.out.println(unique);
}
}
Cookie support is required to access HackerRank
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 →