Given the head of a singly linked list, delete the first node (the head) and return the head of the modified list.
After removing the front node, the node that was second becomes the new head. Detach the old head cleanly — its next pointer should no longer reference the list.
If the list has a single node, deleting the head leaves an empty list, so you return an empty (null) head.
head at head.next, detach the old node, and return the new front — all in constant time.next to null — that's O(n) because a singly linked list has no back pointer.next past the target — O(k) traversal followed by an O(1) splice.Input: head = [1, 2, 3, 1, 7] Output: 2 -> 3 -> 1 -> 7 The first node (value 1) is removed, leaving 2 -> 3 -> 1 -> 7.
Input: head = [1, 5, 7, 8, 99, 100] Output: 5 -> 7 -> 8 -> 99 -> 100 Dropping the front node leaves 5 -> 7 -> 8 -> 99 -> 100.
- 1 <= number of nodes <= 10^5 - 1 <= node value <= 10^5
Deleting the head of a linked list is the smallest possible taste of pointer surgery — and it hides the single idea every list operation leans on: the list is only ever as long as whatever the head pointer points to. Move that pointer and the front node simply vanishes from the list.
next pointer to the following node; the last node's next is null.head — whatever it points to is the first node, and everything reachable from there is the list.In plain terms: the new list starts at the second node. Set head to head.next, detach the old front, and you're done.
Worked example — head = [1, 2, 3, 1, 7]
before: head → [1] → [2] → [3] → [1] → [7] → null
^ delete this
step: new_head = head.next (points at [2])
old head's next set to null (detached)
after: head → [2] → [3] → [1] → [7] → null
answer: 2 -> 3 -> 1 -> 7
A good engineer confirms the shape of the input before writing a single pointer move — a wrong assumption about emptiness is where list bugs hide.
“Is the list guaranteed to be non-empty?”
The constraints promise at least one node, so you never receive a null head — but confirming it tells the interviewer you thought about it.
“What should I return if the list has exactly one node?”
Deleting its only node yields an empty list, so the answer is a null head — the most common thing people forget.
“Do I need to actually free or null out the removed node?”
The task says to detach the old head; in languages with manual memory you also free it, which signals care about leaks.
Before I start, let me confirm a couple of things.
The constraints guarantee at least one node, so head is never null on input — correct?
And if there's only one node, deleting the head should return an empty list, meaning a null head.
A linked list has no separate 'container' — it is exactly whatever head points to. So removing the first node isn't about deleting data; it's about pointing head one node further along.
head → [A] → [B] → [C] move head to B: head → [B] → [C] ([A] is simply no longer reachable)
Every node after the head keeps its exact position and pointers. Nothing downstream changes, so there is nothing to walk — the operation touches one pointer and is O(1).
| Rebuild the list | Repoint the head | |
|---|---|---|
| Idea | Copy every node from the 2nd onward into a fresh list | Set head = head.next, detach the old node |
| Time | O(n) | O(1) |
| Space | O(n) | O(1) |
The rebuild works but pays O(n) time and memory to recreate what already exists. The optimal move changes a single pointer — see the full code in the Approaches selector below.
Key takeaway
To remove the front of a linked list, advance head to head.next and detach the old node. Because the list is defined by its head pointer, this is a constant-time repoint — no scanning, no copying.
if head is null: return null new_head = head.next head.next = null # detach (and free in manual-memory languages) return new_head