Skip to main content
LeetCode 3217, Medium. Topics: Array, Hash Table, Linked List. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:

Problem

You are given an array of integers nums and the head of a linked list. Return the head of the modified linked list after <strong>removing</strong> all nodes from the linked list that have a value that exists in nums.

Examples

Example 1
Example 2
Example 3

Constraints

  • 1 <= nums.length <= 10<sup>5</sup>
  • 1 <= nums[i] <= 10<sup>5</sup>
  • All elements in nums are unique.
  • The number of nodes in the given list is in the range [1, 10<sup>5</sup>].
  • 1 <= Node.val <= 10<sup>5</sup>
  • The input is generated such that there is at least one node in the linked list that has a value not present in nums.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026