DSA interview question
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).
Node* deleteMiddle(Node* head); // removes the node at index floor(n / 2); returns the new head
| Input list | Output list | Explanation |
|---|---|---|
1 -> 3 -> 4 -> 7 -> 1 -> 2 -> 6 | 1 -> 3 -> 4 -> 1 -> 2 -> 6 | n = 7, remove index 3 |
1 -> 2 -> 3 -> 4 | 1 -> 2 -> 4 | n = 4, remove index 2 |
2 -> 1 | 2 | n = 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.)
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 interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in