@@ -0,0 +1,2283 @@
+package java_problems.data_structures;%0D%0A%0D%0Aimport java.util.*;%0D%0A%0D%0A/*%0D%0A * Problem Statement: %0D%0A * In computer science, a double-ended queue (dequeue, often abbreviated to%0D%0A * deque, pronounced deck) is an abstract data type that generalizes a queue,%0D%0A * for which elements can be added to or removed from either the front (head) or%0D%0A * back (tail).%0D%0A * %0D%0A * Deque interfaces can be implemented using various types of collections such%0D%0A * as LinkedList or ArrayDeque classes. For example, deque can be declared as:%0D%0A * %0D%0A * Deque deque = new LinkedList%3C%3E();%0D%0A * or%0D%0A * Deque deque = new ArrayDeque%3C%3E();%0D%0A * %0D%0A * In this problem, you are given N integers. You need to find the maximum%0D%0A * number of unique integers among all the possible contiguous subarrays of size%0D%0A * M.%0D%0A * %0D%0A * Note: Time limit is 3 second for this problem.%0D%0A * %0D%0A * Input Format: %0D%0A * The first line of input contains two integers N and M: representing the total%0D%0A * number of integers and the size of the subarray, respectively. The next line%0D%0A * contains N space separated integers.%0D%0A * %0D%0A * Constraints: %0D%0A * 1 %3C= N %3C= 100000%0D%0A * 1 %3C= M %3C= 100000%0D%0A * M %3C= N%0D%0A * The numbers in the array will range between %5B0,10000000%5D.%0D%0A * %0D%0A * Output Format: %0D%0A * Print the maximum number of unique integers among all possible contiguous%0D%0A * subarrays of size M separated by a space.%0D%0A * %0D%0A * Sample Input: %0D%0A * 6 3%0D%0A * 5 3 5 2 3 2%0D%0A * %0D%0A * Sample Output: %0D%0A * 3%0D%0A */%0D%0Apublic class JavaDeque %7B%0D%0A%0D%0A    public static void main(String%5B%5D args) %7B%0D%0A        %0D%0A    %09Scanner in = new Scanner(System.in);%0D%0A        Deque%3CInteger%3E deque = new ArrayDeque%3C%3E();%0D%0A        int n = in.nextInt();%0D%0A        int m = in.nextInt();%0D%0A        int maxUnique = 0;%0D%0A        int currentUnique = 0;%0D%0A%0D%0A        for (int i = 0; i %3C n; i++) %7B%0D%0A            int num = in.nextInt();%0D%0A            if (!deque.contains(num)) %7B%0D%0A                currentUnique++;%0D%0A            %7D%0D%0A            deque.addLast(num);%0D%0A            if (deque.size() %3E m) %7B%0D%0A                if (!deque.contains(deque.removeFirst())) %7B%0D%0A                    currentUnique--;%0D%0A                %7D%0D%0A            %7D%0D%0A            if (currentUnique %3E maxUnique) %7B%0D%0A                maxUnique = currentUnique;%0D%0A            %7D%0D%0A        %7D%0D%0A        System.out.println(maxUnique);%0D%0A        in.close();%0D%0A    %7D%0D%0A%7D

Add JavaDeque