Hi everyone, let's do this question.
You are given the head of a sorted singly linked list.
Write a function that will take the given head as input.
Delete all nodes that have a value that is already the value of another node, so that each value appears
one time only and return the linked list which is still to be sorted.
A sorted linked list.
All right, so we are given a linked list, a singly linked list.
And we need to delete all the duplicate values and return it.
So that's the question.
Now if you get this question in the interview feel free to ask any clarifying questions you may have.
Now let's proceed and write some test cases to understand what the question asks us.
And what's the expectation.
Let's say the singly linked list which is given to us is this one.
So we have a node with value one which is pointing to a node with value two.
Again, that's pointing to another node with value two, and so on and so forth.
So we can see that this is repeating right.
And again over here we have the same value occurring three times.
So if this is the input the output would be one pointing to two pointing to three pointing to four.
And that points to null.
So there is no repeating value.
So that's what we need to achieve in this question.
Now do give it a thought on how you could solve it.
Now again remember the interesting thing over here is that the singly linked list is sorted.
So that's mentioned in the question.
So think about how you can make use of this also while you solve this question.