Skip to content
Decoder

Delete the Middle Node of a Linked List

Medium

Problem

You get the head of a linked list with n nodes. Delete the middle node, the one at 0-based index n // 2 (round down), and return the head of the changed list. With an even count that is the second of the two middle nodes. If the list has only one node, deleting it leaves an empty list.

Example 1

Input
1
Output
3 -> 4 -> 7 -> 1 -> 2 -> 6 → 1 -> 3 -> 4 -> 1 -> 2 -> 6
Why
index 3 removed

Example 2

Input
1
Output
2 -> 3 -> 4 → 1 -> 2 -> 4
Why
index 2 removed

Example 3

Input
2
Output
1 → 2

Return None (null in TypeScript) when nothing is left.

Constraints

  • 1 <= number of nodes <= 10^5
  • 1 <= Node.val <= 10^5

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.