Magicsheet logo

Delete Node in a Linked List

Medium
38.4%
Updated 6/1/2025

Delete Node in a Linked List

1. What is this problem about?

The Delete Node in a Linked List interview question is a "think outside the box" challenge. Usually, to delete a node, you need access to its predecessor. However, in this Delete Node in a Linked List coding problem, you are only given access to the node that needs to be deleted itself. You do not have the head of the list or the previous node.

2. Why is this asked in interviews?

Companies like Apple and Meta use this question to see if a candidate can find creative solutions when standard constraints (like needing the previous node) aren't met. It’s a test of how well you understand the underlying data structure—that a node's "identity" is just its value and its next pointer.

3. Algorithmic pattern used

This problem uses a Value-Copying and Pointer-Skipping trick. Since you can't truly "delete" the current memory address without the previous node, you effectively "become" the next node.

  1. Copy the value of the next node into the current node.
  2. Update the current node's next pointer to skip the next node (pointing to the one after it).

4. Example explanation

List: 4 -> 5 -> 1 -> 9. You are given the node with value 5.

  1. Current node has value 5, next node has value 1.
  2. Change current node's value to 1. (List looks like 4 -> 1 -> 1 -> 9).
  3. Change current node's next to point to 9. Resulting List: 4 -> 1 -> 9. The node with value 5 is gone.

5. Common mistakes candidates make

  • Trying to find the previous node: Spending time trying to traverse from somewhere unreachable.
  • Not copying the value: Only changing the pointer, which would result in the wrong value being removed.
  • Last node case: Forgetting that this trick doesn't work for the very last node in the list (though the problem usually specifies the node won't be the tail).

6. Interview preparation tip

This is a "brain teaser" style Linked List interview pattern. Whenever you feel stuck because you lack a reference (like a parent or previous pointer), ask yourself: "Can I move the data instead of moving the pointer?"

Similar Questions