A ticket queue is a singly linked list, front to back. Remove the single node that is m-th from the END of the queue (m = 1 means the very last ticket, m = 2 means the second-to-last, and so on). It is guaranteed that 1 <= m <= n. Print the remaining tickets in order (print an empty line if the queue becomes empty).
Line 1: an integer n — the number of tickets.
Line 2: n space-separated integers — the ticket numbers, front to back.
Line 3: an integer m — the position from the end of the ticket to remove.
n - 1 space-separated integers: the remaining tickets in order (an empty line if none remain).
Example 1
Input
5 1 2 3 4 5 2
Expected
1 2 3 5
Explanation
The 2nd ticket from the end is 4 (index 3, 0-based); removing it leaves 1 2 3 5.
Example 2
Input
1 9 1
Expected
(empty)Explanation
The only ticket is removed, leaving an empty queue.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →