Trains the technique from
LeetCode 888Fair Candy SwapThis 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.
Two depots hold crates whose weights read mine and yours. The two depots carry different totals.
Swap exactly one of my crates for exactly one of yours so that afterwards both depots carry the same total. At least one such swap is possible.
Return the pair [a, b], where a is the weight of the crate leaving my depot and b the weight of the crate leaving yours. Where several swaps work, return the one whose a is smallest, and among those the one whose b is smallest.
Example 1
My depot carries ninety and yours eighty-four, so the crate I give up has to be three heavier than the one I take. Handing over 24 for 21 leaves both depots at eighty-seven. My lighter crates, 4, 10 and 17, have no partner three lighter among yours.
Example 2
Mine total twelve and yours eight, so I hand over a crate two heavier than the one I take. Giving up 4 for 2 leaves both at ten. Giving up my 2 would need a crate of nothing to come back.
Example 3
Mine total ten and yours six, so again the outgoing crate is two heavier. Both swaps work here, 3 for 1 and 7 for 5, and the rule asks for the one whose outgoing crate is lighter.
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 fair_candy_swap(mine: list[int], yours: list[int]) -> list[int]:public int[] fairCandySwap(int[] mine, int[] yours)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.