Trains the technique from
LeetCode 2095Delete the Middle Node of a Linked ListThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Pallets on a tow line are coupled nose to tail, each one hitched to the next. The line is handed to you as chain, the list of pallet tags read from the front of the line to the back, so chain[0] is the leading pallet.
Uncouple the middle pallet and close the gap by hitching its predecessor straight to its successor. Numbering the pallets 0, 1, 2, ... from the front, the middle pallet is the one at position floor(n / 2), where n is how many pallets are on the line. A line of one pallet loses that pallet and ends up empty.
Return the tags of the pallets still on the line, front to back. Aim for O(n) time and O(1) extra space beyond the line you return.
Example 1
Five pallets, so the middle one sits at position floor(5 / 2) = 2, which is the pallet tagged 9. Pallet 5 is hitched to pallet 2 in its place.
Example 2
Six pallets, so position floor(6 / 2) = 3 goes, which is the pallet tagged 3.
Example 3
One pallet sits at position floor(1 / 2) = 0, so the line ends up empty.
Example 4
Two pallets, so position floor(2 / 2) = 1 goes, which is the second of the two identical tags. The remaining pallet keeps its place at the front.
Example 5
Three pallets, so position floor(3 / 2) = 1 goes, which is the pallet tagged 20.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def drop_middle(chain: list[int]) -> list[int]:public int[] dropMiddle(int[] chain)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.