Hi, everyone, welcome back.
So in this video, we are going to write the code for this problem case, our telling list.
So our approach was, if this is the last one, four five second one is one three four and the third
one is 26.
So we discussed that.
What we need to do, we need to create one minimum because we want a minimum element each time and we
will insert all these values in our minimum.
Keep one thing to note here is the type of minimum.
So basically the input is, listen, Wildstar.
So this is not in German.
This is old one.
This is one note.
This is another node.
Right.
So my minimum, he will be of type node and not integer.
So we discussed that we need to create one priority queue.
And the pressure to give will be minimum.
So it will be of the type no.
Right.
This is our priority queue.
So this is actually an index for Mexi and not minimum.
We need to create minimum EHP.
So we will come back to this line later that how to create a minimum job.
But for now, let's assume this is my minimum.
Now what I need to do, I need to insert the values.
So let's I trade.
List Nazis and I placeless what I need to do, I need to push these values in my priority queue.
So Picador push list of I write.
So what will happen?
So basically, I have pushed all these values.
So I have pushed no one in my priority queue, I have no one in the priority queue and I have No.
Two in the priority queue, and we discussed that we will run the loop while the priority queue doesn't.
While the priority is not empathy, right.
While the priority queue is containing elements, I will I'll trade.
So let's I'll trade while the priority queue is not empty.
So what do we need to do here?
List North Star, let's name it, temp Bambury A. This is basically your pick your top, right.
And we need to remove this.
Also pick your date, Pop.
And what do you want to return?
We want to return the head head of the newly created linked list.
So list North Star Head, which is initially null.
Similarly, we discussed that I will have one deal that is also null initially.
So after removing this beacon, art, pop, if this is the first element, so if my head is in my head
is nil, that means this is the first node.
So my head and tail both will point towards this node.
Right.
Otherwise, if this is not the first node, what I'm going to do.
I will make the connection so they'll add an extra stamp and I'm going to update my tail pointer, right,
I'm inserting it.
Bill, what else do we need to do here?
See what I'm doing in my head until the board, until they head, until butat initially.
So what I'm doing here is pick the first node.
So the minimum notice when one or two.
Which one is minimum.
These two are same.
So we can pick any let's say I am picking this so I will pick this node and this is the first node head
until the board.
So if the head until the blue tunnel.
So what I'm doing, my head will point to this node and then we also point towards this node that if
this is another node, let's say I have a list of nodes and this is my tail pointer.
So if I have any of the node, then that will not be null.
Had will be pointing towards this node remove tail from here.
So in that case, what I am doing, I am inserting the node, I am inserting the node at the tail position
and then I am updating tail.
So then I am updating might be all right.
So that's how it is working.
But this is not enough.
What else do we need to do?
So we discussed that.
Then we will pop three.
So sorry.
Then we will pop this.
Norvan, what I will do, I need to insert four, I need to insert four.
Right.
So we need to insert.
So what I can do, I can sort that is be good Bush next next of one and next of one is for right.
Similarly, I think this quote is not correct way, because for this node, for this node, what is
next?
Next is null.
So what we will be doing, you will be inserting null and which is wrong.
So you should have one check here that you will not insert values.
Right.
So we should not insert null values.
So before inserting, we must check whether the next is normal or not.
So if the next is not null, then only you will insert.
Right, and one more thing we are inserting here also.
So whatever list of why does not exist, what if this is all right?
It can be also.
So you need to check here also, when a list of IP is not null, then only we will insert in the priority
queue.
We will not and certainly values in the prior to do so, we need to check here.
Right.
And finally, what you will do, you will return did fine.
So let me try to explain you what we are doing.
We discussed that we need to create a minimum heap, but this is not the code for minimum heap.
This is the code for Makhzoumi.
So we will be updating the code a little bit later then.
But we need to do we need to insert these first value in the player dequeue.
So am I trading and if the value is not nil.
So yes, link list exist.
Linked list exist, linked list exist.
So I will push so I will push one, one and two.
Right.
So my priority will contain here when one and two these are nodes and not integer values.
Then I need two pointers had until as I explained in previous we do and finally I answer will be held.
Right.
So what we are doing take the top element, basically the minimum value and remove the minimum value.
And after removing the minimum value, you can check if this is the first node, you will update it
until if this is not the first node, then you will insert at bill and even a battle.
And what else do we need to do so after removing one?
So the next one is four.
So you should insert food, but before inserting four, you need to check whether next is an alternate.
So for example, in case of five, in case of prayer, in case of six here, the next value will be
none so vital.
Insert the prior to.
So we need to write this check that will not insert null values in priority.
Simple.
So the only thing remaining in this code is basically to write, to basically update this line.
We want to create a minimum heap.
Right.
And this is a little bit complex or basically this is something very specific to C++ programming language.
So the syntax for creating minimum heap is basically this.
We need to list North Star.
And we need to pass.
A compare function, and now this will become your minimum heap.
And what is this, my campaign slogan to define what is my campaign?
So the syntax for defining this is basically struct might compare and then you need to write this function.
Bool Operator.
So this bull operator function takes two arguments and one of those arguments that will be this late
analyst least that work prior to Google Contin.
So we need to pass two arguments.
A and B name can be anything.
It doesn't matter.
List an all star and B, and then you need to return a boolean value.
So the value of E should be greater than value of B.
Right, this is the code for creating minimum.
I know this is a little bit complex, but this is the syntax, right?
And we need to remember the syntax.
So we need to create a minimum heap.
So you need to write that type.
The type of elements, a particular store, it will store one at least not start.
Then you need to write this.
So I forgot to close this bracket then comma and then might compare.
Then you need to write struct my compare unit to write bool operator you need to write this index and
Q is of type list Northstar.
So that's why I type here.
And you need to compare to values on what basis you want to compare elements in the prior to.
Q So I want to compare the elements on basis of their values, so I'm comparing the element on basis
of their values.
So this is minimum heap, right.
Values means integer.
So it is given this is the value.
Right.
I know it's a little bit complex, but this is the syntax very specific to C++ and other programming
languages.
You can find different defensive backs.
But what I suggest is basically do not complicate things.
Do not do not try to indulge in and try to learn why this is the syntax.
Just remember the syntax that this is how we write minimum heap and we can move forward.
This is more than enough, right?
So this is the entire goal for solving this problem.
And before submitting, let's first run so that if there is any bug, we can figure it out and we can
fix the bug.
And if everything works fine, then obviously we will submit.
OK, so we need to write actually a column here.
And yet, obviously, I told you that we need to close this record.
So now let's listen to it.
I think it will work fine now.
So we got competition out of here because this must be semicolon.
Yep, so basically our goal is working.
So this is very simple problem, I don't know why they have mentioned it as hard, but this was really
simple.
Right now, one more thing that I want to discuss before ending this video is the other variation of
this problem.
So what the interviewer will say so let's say you have hundreds of data interviews, says you have hundreds
of data, and we want to sort this data.
Right.
So one obvious approach that you will give him is basically sir or ma'am, I can sort this data with
the help of my chart or with the help of quicksort or any other sorting algorithm.
He will say it's fine, right?
It's fine.
It will work.
But now he modified the question and he's giving one limitation that at one time in my memory, you
can load only tangible data.
So if we can load MGB of data at one time, then how much it will be able to sort of data that.
You got my point.
So I'm repeating myself.
The interviewer is saying you have a limitation.
At one time in my memory, you can have only tangible data.
So this much certain quicksort will have access to tangible data only.
So it will start on the tangible data.
But the problem is we want to store hundreds of data, thousands of data.
So how we can do that?
This is the question.
So what we can do?
For example, if I have hundreds of data and I can load only tangible data at one time in my memory,
so I will divide this hundred into fences, into ten parts, and each part contains tangible data rate.
So tangible data and then parts.
Right.
So what I will do next, I will pick one part and I will load it in the memory and my will sort that
part right.
So one by one, I will look at all the 10 parts.
And finally, what we will have.
So finally we will have 10 sorted parts, right.
Then sorted parts.
And each part is basically storing tangible data, 10 GB of sorta data.
And then the problem statement is this only we have sorted data rate.
We have 10 GB sorted data, 10 parts, and we need to merge them.
We have 10 sorta data and then parts, and we want to merge them so we can use this algorithm for merging
10 parts, then sorted parts, right.
So this is the other way.
And this this is the other way in which this problem can be fixed.
Right.
So that's how you can solve this problem.
So this is all that I want to discuss.