First negative integer in window of k

why we are not directly using queue and using linked list as a queue.

The internal implementation of java uses Queue as a LinkedList so you have to use that. And i don’t understand exactly what you mean by directly using queue?

I mean to say isn’t there any inbuilt class to directly use Queue just like we use for Hashmap or Stack.
and moreover before studying linkedlist we used ArrayList to code queue which is faster, then why have java implimented it using linkedList which is slower then ArrayList.

Alright, let me give you an explanation. Queue is an interface in Java, from which concrete classes like LinkedList and ArrayDeque implement. So, you cannot instantiate Queue by itself, instead you need to instantiate its implementations. As far as performance issues are concerned, if you are just using the queue for accessing the first or last element or adding at the first or last, ArrayDeque is significantly faster and less memory overhead than LinkedList. So for applications like in BFS, use ArrayDeque instead of LinkedList.

1.So,Bhaiya suppose we doing questions on hacker rank we need to use Queue then how we are going to use it.Are we going to use the class we have written(in our course) and copy paste it or we are going to use ArrayDeque.
2. How we are going to use graph do we have any concrete classes for it or we are going to copy paste our implimentation.

Don’t use your custom made classes unless , there’s some added functionality in it on top of built in class or there’s no built in class available for the purpose. Built in classes are highly optimised and provide all sorts of exception handling, so prefer using them. Use it like this, Queue queue = new ArrayDeque<>();
For graphs just use an array of lists or lists of lists as adjacency list and no need to create another custom class

I didn’t understand the graph part,
How we are going to instantiate graph?
Like we did for queue

ArrayList[] adj = new ArrayList[n];

Bhaiya but this the declaration of Arraylist.How it is behaving as a graph
How we are going to have edges and nodes.

And how we are going to use arraylist functions to perform function of graph such as numVertex and other functions of graph

This is graph represented as an adjacency list. Now, if i have an edge from node x to node y, simply do adj [x].add(y) (for directed graph). The degree of each vertex is simply the size of its list i.e. adj[x].size()

It’s getting confusing :confused:

have you read graphs and all the algos related to it ?

Yes I have. I have completed Graphs section and it’s implementation including Heap and HashMap.
My main concern is when working on a project I will use external libraries like JGraphT for graphs but when doing question online How I am going to solve graph related questions. Where I am just given a function to wrote my logic.
When I don’t have inbuilt class.
Like we have for stack,Hashmap
We can use ArrayDeque for Queue.
But what’s the solution for graph related questions.how a arraylist of arraylist can be treated as graph.
How arraylist will implement algos like djikstra, How we will perform functions like bfs in arraylist.