Problem 381
Delete the Middle Node
Medium · 20 pts · Linked List, Two Pointers
Problem
Delete the middle node of a singly linked list and print the list that remains. For a list of N nodes, the middle node is the one at position floor(N / 2), counting from 0. So for N = 4 the node at position 2 is removed, and for N = 5 the node at position 2 is removed too. A list with a single node becomes empty. Two pointers moving at different speeds find the middle in one pass.
Input
The first line contains N, the number of nodes. The second line contains the N node values from head to tail.
Output
Print the node values of the resulting list from head to tail, separated by spaces, or EMPTY if the list has no nodes.
Constraints
1 <= N <= 100000; 1 <= value <= 100000
Example input
7 1 3 4 7 1 2 6
Example output
1 3 4 1 2 6
Explanation
The list 1 3 4 7 1 2 6 has 7 nodes, so the middle is position floor(7 / 2) = 3, the node with value 7. Removing it leaves 1 3 4 1 2 6.