2Brute2Best
🔥0

Delete the Middle Node of a Linked List

Medium·LeetCode #2095 Pro OnlySlight Variation
LeetCode
01

Problem Statement

You are given the head of a singly linked list with n nodes. Remove the middle node and return the head of the changed list.

The middle node is the one at index ⌊n / 2⌋, counting from 0. So for an even length it is the second of the two middles. For example: n = 1 → index 0, n = 2 → index 1, n = 4 → index 2, n = 5 → index 2.

Input

head, the first node of a singly linked list.

Output

The head of the list after the middle node has been removed (null if nothing is left).

Example 1
Input: head = [1, 3, 4, 7, 1, 2, 6]
Output: [1, 3, 4, 1, 2, 6]

n = 7, so the middle is index 3, the node with value 7. It is removed.

Example 2
Input: head = [1, 2, 3, 4]
Output: [1, 2, 4]

n = 4, so the middle is index 2, the node with value 3.

Example 3
Input: head = [2, 1]
Output: [2]

n = 2, so the middle is index 1, the node with value 1.

Constraints
  • • The list has between 1 and 10^5 nodes.
  • • 1 ≤ Node.val ≤ 10^5
02

Pattern Recognition Clues

Recognising these key signals in the problem description immediately identifies the pattern:

“middle node (index ⌊n/2⌋)”
→ Halfway along a list of unknown length → slow/fast.
“delete / remove”
→ In a singly linked list you remove a node through the node **before** it → stop slow one node early.
“return the head”
→ The head only changes when the list has 1 node, so handle that case first.
03

Approach Complexity Ladder

Brute Force — count, then walk to the node before the middleO(N)O(1)

Count n, walk n/2 − 1 steps, skip the next node

Optimal — slow/fast with a head startO(N)O(1)

Start fast at head->next->next so slow stops one node before the middle

Brute Force Intuition

Count the nodes to get n. The middle is at index n / 2, so the node before it is at n / 2 − 1. Walk there from the head and set its next to skip the middle.

Recognition rule for this sub-pattern:

When fast reaches the end, slow is in the middle. Use this to split a list in half.
Remember this · Linked List — Fast & Slow
Trigger
Cycle detection, middle of list, "n-th from end", two lists meeting, repeating sequences.
Think
If one pointer moves faster or starts earlier, where will they meet?
Key question
What speed or gap makes the meeting point tell me the answer?
Brute2Best Pro Content

Unlock Complete Visual Walkthrough & Optimal C++

The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.

All 440 visual dry runs & algorithms
Interactive step-by-step playback with pointer & array state transitions
52 comprehensive LLD chapters
Interactive UML diagrams, real-world stories (Food Delivery, Trading, RPG), and practice solutions
40 C++ basics labs & hardware memory models
Vtables, byte layouts, assembly insights, and multi-threading race conditions
Production-ready C++23 source code
Modern idioms, clean contracts, time/space complexity derivations, and interview takeaways

First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.

Beyond The LeetCode Problem

How this concept connects to System Design & C++ Systems

Bridge DSA with production engineering

Top engineering interviews test whether you understand how algorithms like Linked List — Fast & Slow translate into production architectures and low-level memory mechanics.