Trains the technique from
LeetCode 3069Distribute Elements Into Two Arrays IThis 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.
Parcels come off a chute one after another, their weights listed in weights. No two parcels weigh the same. A sorter stacks them on two trays, each new parcel going on top of the tray it is sent to.
The first parcel goes on the near tray and the second on the far tray. Every parcel after that is placed by looking at the parcel currently on top of each tray: if the near tray's top parcel is heavier than the far tray's top parcel, the new parcel goes on the near tray, and otherwise it goes on the far tray.
Return one list holding the near tray read from the bottom up, followed by the far tray read from the bottom up.
Example 1
Parcel 7 goes near and parcel 4 goes far. Parcel 9 arrives with tops 7 and 4, so it goes near; parcel 2 arrives with tops 9 and 4, so it goes near; parcel 6 arrives with tops 2 and 4, so it goes far. The near tray reads 7, 9, 2 and the far tray reads 4, 6.
Example 2
Parcel 7 arrives with tops 9 and 8 and goes near. Parcel 6 then arrives with tops 7 and 8 and goes far, leaving the near tray as 9, 7 and the far tray as 8, 6.
Example 3
Parcel 3 arrives with tops 4 and 100 and goes far. Parcel 99 then arrives with tops 4 and 3 and goes near, and parcel 2 arrives with tops 99 and 3 and goes near.
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 split_parcels(weights: list[int]) -> list[int]:public int[] splitParcels(int[] weights)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.