You are viewing a single comment's thread. Return to all comments →
Time out limit is driving me crazy in the bad way. First time run code breaks at #9 #10 test case, but second time ahead only in #10
public static void main(String[] args) { Scanner in = new Scanner(System.in); Deque deque = new ArrayDeque<>(); int arraySize = in.nextInt(); int subArraySize = in.nextInt(); Set<Integer> setInteger = new HashSet<>(); int maxUniqueNumber = setInteger.size(); for (int i = 0; i < arraySize; i++) { int num = in.nextInt(); deque.offerLast(num); } while(deque.size() >= subArraySize){ int i = 0; for(Object d : deque){ i++; setInteger.add((Integer)d); if(i == subArraySize){ break; } } maxUniqueNumber = Math.max(setInteger.size(), maxUniqueNumber); setInteger.clear(); deque.poll(); } System.out.println(maxUniqueNumber); in.close(); }
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 →
Time out limit is driving me crazy in the bad way. First time run code breaks at #9 #10 test case, but second time ahead only in #10