Grokking the Art of Recursion for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
15. Removing Nodes From Linked List
On this page

Problem Statement

Examples:

Try it yourself

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 #InputExpected OutputDescription
11 -> 2 -> 3 -> 4 -> 21 -> 3 -> 4Remove all nodes with value 2 from the list.
22 -> 2 -> 2 -> 2 -> 2nullRemove all nodes with value 2 from the list.
31 -> 3 -> 5 -> 71 -> 3 -> 5 -> 7No 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