Back to course home
0% completed
Vote For New Content
15. Removing Nodes From Linked List
Problem Statement
Write Recursive Approach for Removing Nodes From Linked List.
Given a singly linked list and a target value, write a recursive algorithm to remove all nodes from the linked list that have the target value.
Examples:
Sr # | Input | Expected Output | Description |
---|---|---|---|
1 | 1 -> 2 -> 3 -> 4 -> 2 | 1 -> 3 -> 4 | Remove all nodes with value 2 from the list. |
2 | 2 -> 2 -> 2 -> 2 -> 2 | null | Remove all nodes with value 2 from the list. |
3 | 1 -> 3 -> 5 -> 7 | 1 -> 3 -> 5 -> 7 | No nodes with value 2 exist in the list. |
Constraints:
- The number of the nodes in the given list is in the range [1, 10<sup>5</sup>].
- 1 <= Node.val <= 10<sup>5</sup>
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples:
Try it yourself