Challenge: Deletion in Singly Linked List (Delete by Value)

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

Delete by Value

This operation deletes the required node, e.g., n, from any position in a Singly Linked List. This deletion follows the following steps:

  1. It takes in the value that needs to be deleted from the list.
  2. It traverses the list searching for that value.
  3. Once the node (n) with the required value is found, it connects n's previous node to the nextNode of n.
  4. It then removes n from the list.

Here’s an illustration of how this type of deletion works in a linked list:

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