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 #

Implement the Delete functionality. In this function, we will pass a particular value that we want to delete from the list. The node containing this value could be anywhere on 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 value to be deleted.

Output #

true if the value is deleted, false otherwise.

Sample Input #

LinkedList = 1->2->3->4->5
Value = 4

Sample Output #

true

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