Interview Questions/Coding/Audit Chain Middle Removal

Audit Chain Middle Removal

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Audit Chain Middle Removal

A compliance chain is represented as a singly linked list. During review, the system must remove the middle checkpoint from the chain. If the chain has length n, the checkpoint removed is at zero-based index floor(n / 2). For even lengths, this means the second of the two central nodes is removed. The relative order of all other nodes must remain unchanged. Input Format: You are given the head of a singly linked list. Output Format: Return the head of the linked list after removing its middle node. If no nodes remain, return null.

Examples

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

Explanation: The middle index is floor(7 / 2) = 3, value 7. Removing it leaves 1 3 4 1 2 6.

Approach hint

Keep a pointer to the node before the slow pointer.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp