Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this Java question: Ja a Dequeue. We are given a code to work with and please use Java 8 to answer

Please help me with this Java question: Ja a Dequeue. We are given a code to work with and please use Java 8 to answer the question.

image text in transcribed

image text in transcribed

Here is a code we are given to work with.

import java.util.*;

public class test {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

Deque deque = new ArrayDeque();

int n = in.nextInt();

int m = in.nextInt();

for (int i = 0; i

int num = in.nextInt();

}

}

}

In computer science, a double-ended queue (dequeue, often abbreviated to deque, pronounced deck) is an abstract data type that generalizes a queue, for which elements can be added to or removed from either the front (head) or back (tail). Deque interfaces can be implemented using various types of collections such as LinkedList or ArrayDeque classes. For example, deque can be declared as: Deque deque = new LinkedList (); or Deque deque = new ArrayDeque (); You can find more details about Deque here. In this problem, you are given N integers. You need to find the maximum number of unique integers among all the possible contiguous subarrays of size M. Note: Time limit is 3 second for this problem. Input Format The first line of input contains two integers N and M : representing the total number of integers and the size of the subarray, respectively. The next line contains N space separated integers. Constraints 1N1000001M100000MN The numbers in the array will range between [0, 10000000]. Output Format Print the maximum number of unique integers among all possible contiguous subarrays of size M. Explanation In the sample testcase, there are 4 subarrays of contiguous numbers. s1=5,3,5 - Has 2 unique numbers. s2=3,5,2 - Has 3 unique numbers. s3=5,2,3 - Has 3 unique numbers. s4=2,3,2 - Has 2 unique numbers. In these subarrays, there are 2,3,3,2 unique numbers, respectively. The maximum amount of unique numbers among all possible contiguous subarrays is 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions