Hi, everyone, welcome to this new video.
So in this video, we are going to solve this question murder case or telling list.
So in this question, we are provided with an array of killing list and each link is basically sorted
in ascending order.
So if we talk about this, this is my first linked list, one four five second linked list is one three
and four towelling list is 26.
So basically each linked list is started in ascending order rate.
What we need to do, given all this linked list, I need to find one link list which is sorted in ascending
order.
We need to merge.
We need to merge all these linked list into one single short list.
So what will be the single sorted link list?
That will be one one, then two, then three, then four, then five.
We have four actually two times.
Right for this present.
Two times so four, four, five and six.
So given this input, we need to return this.
This is the problem statement.
Now the question is how we can do this.
So basically it's very, very simple.
But I'm going to use I will use prior to dequeue basically minimum heap rate in minimum.
But I will do I will insert these three values initially.
So I will insert node one.
I have another node one, and then I will insert No.
Two.
Right.
Let's say this is the head of the linked list and this is the tale of the linked list.
Right.
So what I will do, I will push the first node of all the link list, so I will push one, one and two
into my minimum.
Correct.
Now what I will do, I will pick the minimum.
I will pick the top element of the player dequeue knights over the top element, either this one or
this one.
So it can be either this or this because the values are the same.
So let's say I am talking about this, this one.
So what will happen since this is the first node, this will be the head and this will also be the deal
right now.
After that, what I will do, I will push the next of this.
I will push for.
So since I took minimum, then I will push for the next element for this.
Right now, again, I will pick the minimum, so for one, two, which one is minimum, one year minimum,
so remove one, I will put one here and I will make this connection.
And this is my deal and this is my head.
Right.
So after picking one, the next element is three.
So I will push three.
Right.
I will push three.
Now my priority queue contains two, three and four.
Which one is minimum.
Two is minimum.
So I will pop two, I will connect two.
I will update my deal and then the next of two is basically six.
So I will push six again for three and six a.m. three years minimum.
So big three make the connection.
Now what will we will make this connection right.
Will update the tail pointer.
What is the next of three next threes for.
So I will insert four now again the minimum will give you the minimum.
So for Forensic's, these two values are seen so we can pick any.
So let's say I am picking this, so this will become four again.
I will update my tail pointer and the next of four is basically five, so I will insert five.
Right now I have five, four and six.
So which one is minimum.
Four is minimum.
So big four.
And what is the next or four.
So next of four is nothing.
So we will not push anything.
So right now my map is containing only two elements, five and six.
So which one is minimum.
Five is minimum.
So I will make the connection.
I will update the tail pointer and release the next top five.
Next of five is nil, so I will not push anything.
Now my priority is only one element, so this will be the minimum element.
I will connect to this.
I will update my tail pointer.
What is the next top six?
Next of six is nil.
So I will not push anything and your priority will become empty.
So when your priority queue becomes empty, you are then you are done.
And what is your answer?
You will return head plate and this is your sorted list.
Right.
So we will return head, so we need to talk head so that we can return this and we need to store tail
so that we can make connections.
Right.
So you can solve this problem very easily using the priority queue, because Pritikin will give you
the minimum element each time.
And we want a minimum element.
So you can write the code for this function, so you can write the code for this problem.
I will be writing the code in the next review.
So this is it.
I will see you in the next one.
Thank you.