Deleting a Node in a Linked List is a well-known interview question because it comes with an unusual constraint. You are not given the head of the linked list. Instead, you are given a reference to a node that must be deleted, and you are told that this node is not the tail.
At first, that sounds impossible. In a normal singly linked list, deleting a node typically requires access to the previous node so you can redirect its next pointer. Without the head, you cannot traverse from the beginning to find the previous node, so the standard deletion technique does not apply.
This is exactly why interviewers ask it. They want to see if you can think beyond “remove the node” and instead focus on “remove the value at this position,” using the tools you actually have.
Why you cannot delete the node in the usual way
In a singly linked list, each node points only forward. There is no pointer to the previous node.
If you had access to the head, you could walk the list until you find the node before the one you want to delete, then bypass it by adjusting links.
But with only the node itself, you cannot reach backward. That means you cannot detach this node cleanly from the chain, because you have no way to tell the previous node to stop pointing to it.
So the problem is not asking you to physically remove the node object in the way you might imagine. It is asking you to make the list behave as if that node were removed.
The key idea behind the solution
Since you cannot remove the node directly, you instead “overwrite” it.
You copy the value from the next node into the current node, and then bypass the next node by changing the current node’s next pointer to skip over it.
After this operation, the original node you were asked to delete now contains the value that used to be in its next node. The next node is removed from the list by being skipped, which is what creates the effect of deleting the original node.
From the perspective of anyone traversing the list, the required value is gone, and the list remains connected.
This works only because the node is guaranteed not to be the tail. If it were the last node, there would be no “next node” to copy from, and you would truly be stuck.
Want to explore more coding problem solutions? Check out the Maximum Product of Three Numbers and Merge Two Binary Trees.
Why this approach is correct
Think about what deletion means in a linked list: it means the sequence of values seen during traversal should no longer include the deleted element, and the list should remain properly linked.
By copying the next node’s value into the current node, you effectively replace the “deleted” value with the value that should come after it.
By skipping the next node, you ensure that the duplicated value does not appear twice.
As a result, the list after the operation has exactly the same traversal result you would have gotten if you had deleted the original node using a previous pointer.
The only difference is internal: the node object that got removed is actually the next node, not the node reference you were given. But the problem’s requirement is based on the list’s behavior, not the identity of node objects.
What this does and does not guarantee
This solution keeps the list valid and removes the targeted value from the list’s sequence.
It does not truly free memory or remove the specific node instance in languages where object identity matters. In typical interview contexts, that distinction is irrelevant because the list is judged by output behavior.
If someone still held a separate reference to the next node, they would now be holding a node that is no longer part of the list. That’s fine and expected under the problem’s constraints.
Performance in simple terms
This operation runs in constant time because it performs a fixed amount of work.
It also uses constant extra space because no additional data structures are needed.
This is one of the rare linked list problems where the intended solution is O(1) and still clean.
Top comments (0)