InterviewPrepKit

Home / Coding / Algorithm & Data Structure / Linked List

Delete the Middle Node of a Linked List

medium Original ↗ 00:00

Problem

Given the head of a singly linked list with n nodes, remove the middle node and return the head of the modified list.

The middle node is the one at index ⌊n / 2⌋ (0-based, counting from the head). So for a list of 1 node you delete the head itself (returning an empty list); for 2 nodes you delete the second; for 7 nodes you delete index 3.

Examples

  • Input: 1 -> 3 -> 4 -> 7 -> 1 -> 2 -> 6 → Output: 1 -> 3 -> 4 -> 1 -> 2 -> 6 n = 7, so the node at index ⌊7/2⌋ = 3 (value 7) is removed.
  • Input: 1 -> 2 -> 3 -> 4 → Output: 1 -> 2 -> 4 n = 4, index ⌊4/2⌋ = 2 (value 3) is removed.
  • Input: 2 -> 1 → Output: 2 n = 2, index 1 (value 1) is deleted.

Constraints

  • Number of nodes is in [1, 10^5].
  • 1 <= Node.val <= 10^5

Think about it first

Hint 1 To delete a node from a singly linked list you must be standing on the node before it. Which index is that here?
Hint 2 Two passes work: count n, then walk to index ⌊n/2⌋ − 1 and bypass the next node. Can you find the middle in a single pass instead?
Hint 3 Run a slow and a fast pointer (1 step vs. 2 steps). When fast reaches the end, slow is at the middle — so if you start slow one node behind (or offset fast), slow lands on the node just before the middle, ready to unlink it.

Write your solution, then hit Run tests to check it — or get a mock grade from the AI coach.

The coach remembers this session — revise your code and ask again, and it grades your progress. It gives hints, not the answer.
Report a bug