Skip to content

3217. Delete Nodes From Linked List Present in Array #493

Discussion options

You must be logged in to vote

We need to traverse through the linked list and remove any nodes that have a value present in the array nums.

Approach:

  1. Hash Set for Fast Lookup: Since checking if a value exists in nums needs to be efficient, we will convert nums into a hash set. This allows O(1) lookup for each value.
  2. Iterate Through the Linked List: We will iterate through the linked list and remove nodes whose values are present in the hash set.
  3. Pointer Manipulation: While iterating, we will adjust the pointers to "skip" nodes that match values in the nums array.

Steps:

  1. Convert nums to a hash set for O(1) lookup.
  2. Traverse the linked list with two pointers: one for the current node and one for the previous node to h…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mah-shamim
Comment options

mah-shamim Sep 7, 2024
Maintainer Author

@basharul-siddike
Comment options

Answer selected by mah-shamim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants