#888
Fair Candy Swap
pupil · 355 · lc easy +23 · verified · 64.6% accepted · 2,265 likes · top 68%
Description
Alice and Bob each own several boxes of candy, and their totals differ. You are given arrays aliceSizes and bobSizes where aliceSizes[i] is the candy count in Alice's ith box and bobSizes[j] is the candy count in Bob's jth box.
They want to swap exactly one box each so that both end up with the same total number of candies.
Return an integer array answer where answer[0] is Alice's box size and answer[1] is Bob's box size in the swap. If multiple answers exist, return any. A valid answer is guaranteed.
Example 1:
Input: aliceSizes = [1,1], bobSizes = [2,2]
Output: [1,2]
Example 2:
Input: aliceSizes = [1,2], bobSizes = [2,3]
Output: [1,2]
Example 3:
Input: aliceSizes = [2], bobSizes = [1,3]
Output: [2,3]
Code
1
2
3