Let's do one leetcode question.
Okay.
So this is the question.
Uh, you can read it out by pausing it once.
Okay.
Just pause and read it out.
I'm stalling it.
So just read out this part and read out this part as well.
Okay, great.
So I hope each and every one of you have read the question once.
Now I will just tell you quickly what the question is saying.
Question is saying that you have this linked list.
You have this linked list okay.
You are not given head.
And it's a medium level question as you can see.
Right.
It's a medium level question.
Now it's saying that okay I am not given any head okay.
But instead what I have been given.
Let me just draw this down here.
What I have been given is a node.
So I'm just given a node and I have to delete.
I have to make sure that I'm deleting this node okay.
So again, I will repeat the question.
I have been given a linked list.
Let's say I have to delete three from here.
Okay, so just now we saw that how we can delete from value.
But this time we are not given any head.
And it is also saying that this node which you have to delete okay.
And rather we have to modify in place, you will see we don't have to even return something.
Right.
This is not tail.
So how you can do that.
Well the approach is very easy.
We have just learned about the value.
All I have to do here is one two.
I have to modify my list so I can modify.
I can say that hey three can you take the value of four.
Can you take the value of four.
So this will become this.
And let's say if I have five six something then I can just delete this from this particular chain.
So actually two line solution is there.
Okay I will just repeat the solution so that it is clear.
Pay attention.
What is it saying.
It is saying that let's say you have a node like this.
You have a linked list like this.
Okay, you want to delete five.
You want to delete five.
And you are given that you have to delete this node only.
This is the node you have been given.
You don't have to return anything.
You don't have to do anything.
But now in this question we saw that how we can also look out and use values as well.
Right.
The data.
So in this it is value.
In our linked list it is data.
And you will see that it is very much same.
Right.
We have just made a node.
It is a list node here.
What I can very easily do I can just say that hey can you please become equal to the next one, the
next which is there.
So we are just copying this data.
Once I have copied I am just breaking this connection.
So just a two line code will work.
If you are very good we can write it in one line as well.
But again I don't count the line as a good solution.
So node dot data.
Sorry dot val is equals to node dot next dot val.
So this works.
Now.
It has given me that this will never be the tail.
If you have read the question when I asked you to, uh, by pausing, you will see that it is not the
last node.
So I can use this because it will not be none.
Right then node dot next is equals to node dot next, dot next.
And yeah this question is done.
So again it's a medium question.
And now you will get it.
Why I was so pushing you on trying out these questions of all the delete and everything just based on
the same concept.
This question has been made and you can do this right.
I don't think it's difficult.
Pretty sure it would have been asked in many good companies as well.
So we can find that out as well.
It is locked.
But yeah.
Okay.
So yeah, you are able to see that we are able to submit our code see beating a lot as well.
But yeah should be fine.
Okay.
So great everyone I hope you like the way we solve this question.
And now you are a lot comfortable in traversing on your linked list.