PPractick

DSA interview question

Delete the Middle Node of a Linked List

Medium · Data structures · Topics: linkedlist, two pointer

The problem

A queue of support tickets is balanced by removing the middle ticket, defined as position ⌊n/2⌋ counting from 0, so for 4 tickets it's the third one and for 7 it's the fourth. Counting first and walking again takes two passes. With fast and slow pointers, you can land slow on the node just before the middle in a single pass by giving fast a two-node head start, and then unlink the middle with one pointer change.

Example: 1 -> 3 -> 4 -> 7 -> 1 -> 2 -> 6 → 1 -> 3 -> 4 -> 1 -> 2 -> 6 (the 7 at index 3 is removed).

Function signature

Node* deleteMiddle(Node* head);  // removes the node at index floor(n / 2); returns the new head

Test cases

Input listOutput listExplanation
1 -> 3 -> 4 -> 7 -> 1 -> 2 -> 61 -> 3 -> 4 -> 1 -> 2 -> 6n = 7, remove index 3
1 -> 2 -> 3 -> 41 -> 2 -> 4n = 4, remove index 2
2 -> 12n = 2, remove index 1
1(empty)n = 1, remove index 0

(Confirm: the middle is index ⌊n/2⌋ (0-based), i.e. the second middle for even lengths (LeetCode 2095); the removed node is freed.)

How interviewers phrase it

Clarifying questions to ask

  1. Which middle for an even length?
  2. What happens for a single node? (The list becomes empty.)
  3. Free the deleted node?

Follow-ups to expect

  1. "Why start fast two nodes ahead?"
  2. "Why can't you just find the middle and delete it?"
  3. "How would a prev pointer work?"
  4. "Complexity?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in