Here is the interview question prompt, presented for reference.
Now that we've implemented a linked list, can you write a method that will delete all nodes of a given value?
You're given the following standard structure as the definition of a linked list node:
class LinkedListNode {
constructor(val) {
this.val = val;
this.next = null;
}
}
The follow scenario is how we would invoke the method with a linked list 1 -> 2 -> 2 -> 5 -> 6. As you can see, running the method results in removing all 2s in the list.
// head = 1 -> 2 -> 2 -> 5 -> 6
// val = 2
removeNodes(head, val);
// 1 -> 5 -> 6
-1000000000 and 1000000000 )O(n)O(1)You can see the full challenge with visuals at this link.
Challenges • Asked almost 8 years ago by Team AlgoDaily
This is the main discussion thread generated for Delete Nodes From A Linked List.