Trains the technique from
LeetCode 870Advantage ShuffleThis 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.
A trade fair runs a head-to-head bench test. There is one slot per machine on each side, and rival[i] is the throughput figure of the rival machine already booked into slot i. The rival booking is published and cannot be changed. mine lists the throughput figures of our own machines, and we may book our machines into the slots in any order we like, one machine per slot.
A slot is won when the figure of our machine in it is strictly greater than the figure of the rival machine in it. Equal figures are not a win.
Return a booking, as an array whose entry i is the figure of the machine we put in slot i, that wins as many slots as possible.
Several bookings may win that same number of slots, so exactly one of them is asked for. Compare two bookings like this: take the slots in decreasing order of their rival figure, putting the earlier slot first when two rival figures are equal, read off the figure each booking put into each of those slots, and at the first place where the two readings differ the booking with the smaller figure there is the smaller booking. Return the smallest booking that wins as many slots as possible.
Example 1
In this booking slot 1 holds our 6 and slot 2 holds our 9, and each of those clears the rival figure of 4, so two slots are won; slot 0 holds our 3, which does not clear 4. All three rival figures are equal, so the comparison reads the slots in the order 0, 1, 2, giving 3, 6, 9.
Example 2
Every figure on both benches is 5, so whichever way our machines are booked each slot pairs 5 against 5, and equal figures are not a win, so no slot is won.
Example 3
Slot 1 holds our 8 against a rival figure of 3, which is a win, and slot 0 holds our 2 against a rival figure of 7, which is not, so one slot is won. Slot 0 has the larger rival figure, so the comparison reads slot 0 first, giving 2, 8.
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 slot_machines(mine: list[int], rival: list[int]) -> list[int]:public int[] slotMachines(int[] mine, int[] rival)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.