Challenge: Deletion by Value

Based on how we handled the deletion at head strategy, let's write the function for deletion by value.

Problem Statement

In this lesson, you’ll be implementing the delete by value strategy. We’ll describe its functionality, which should give you a clearer idea of what you have to do.

In this function, we can pass a particular value that we want to be deleted​ from the list. The node containing this value could be anywhere in the list. It is also possible that such a node may not exist at all.

Therefore, we would have to traverse the whole list until we find the value which needs to be deleted. If the value doesn’t exist, we do not need to do anything.

Input

A linked list and an integer to be deleted.

Output

true if the value is deleted. Otherwise, false.

Sample Input

LinkedList = 3->2->1->0
integer = 2

Sample Output

true

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.