Standard Bar Linked List · Medium Problems of LL O(N) · O(1)
A booking chain lists seats in order, and a cancellation names a seat counted from the rear — awkward on a one-way chain with no length posted. The counter settles it with a two-pointer walk: send one pointer n seats ahead, then advance both until the leader runs out; the follower now stands exactly one seat before the cancellation target.
Input: An array head of node values and an integer n, the distance from the end of the list.
Output: The values of the list after removing the n-th node from the end.
1 <= list length <= 10^51 <= n <= list length-10^9 <= node value <= 10^9Input: {"head":[1,2,3,4,5],"n":2}
Output: [1,2,3,5]
Counting from the rear, the second seat is 4; relinking skips it.
Input: {"head":[1],"n":1}
Output: []
The only seat is cancelled, leaving an empty chain.