Skip to main content
Back to problems
Leetcode
Medium
Linked Lists
Two Pointers
Amazon
Delete The Middle Node Of A Linked List

Remove the middle node from a singly linked list and return the updated head.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.

Delete Middle Node of a Linked List

gfg
Problem Statement

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

For a list with an even number of nodes, delete the second of the two middle nodes.

You should perform the deletion by changing links in the list, not by rebuilding the entire list.

Input Format

  • A singly linked list is given by its head node.
  • Each node contains an integer value and a pointer to the next node.
  • The list contains at least one node.

Output Format

  • Return the head of the linked list after removing its middle node.

Constraints

  • 1n1051 \le n \le 10^5
  • Node values may be any valid integers.
  • The list is singly linked.
  • When nn is even, remove the second middle node.
Examples
Sample cases returned by the problem API.

Example 1

Input

head = [1,3,4,7,1,2,6]

Output

[1,3,4,1,2,6]

Explanation

The list has 7 nodes, so the middle node is 7. Removing it leaves the remaining nodes linked in order.

Example 2

Input

head = [1,2,3,4]

Output

[1,2,4]

Explanation

The list has 4 nodes, so the second middle node is 3. Removing it produces [1,2,4].

Show 1 more example

Example 3

Input

head = [2]

Output

[]

Explanation

A single-node list has its only node as the middle, so deleting it leaves an empty list.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.