Tap here to switch tabs
Problem
Submissions

Problem: Fair Candy Swap

med
30 min
Try to solve the Fair Candy Swap problem.

Statement

Alice and Bob have candy boxes of various sizes, represented by integer arrays aliceSizes and bobSizes, where aliceSizes[i] is the number of candies in the candy box Alice owns at index i, and bobSizes[j] is the number of candies in the candy box Bob owns at index j.

They wish to exchange exactly one candy box each so that, after the exchange, they both have the same total amount of candy.

Return an integer array containing two elements [aliceSizes[i], bobSizes[j]], where aliceSizes[i] is the size of the candy box Alice trades and bobSizes[j] is the size of the candy box Bob trades. If there are multiple valid answers, you may return any one of them.

Constraints:

  • 1≤1 \leq aliceSizes.length, bobSizes.length ≤104\leq 10^4

  • 1≤1 \leq aliceSizes[i], bobSizes[j] ≤105\leq 10^5

  • Alice and Bob have a different total number of candies.

  • There will be at least one valid answer for the given input.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Fair Candy Swap

med
30 min
Try to solve the Fair Candy Swap problem.

Statement

Alice and Bob have candy boxes of various sizes, represented by integer arrays aliceSizes and bobSizes, where aliceSizes[i] is the number of candies in the candy box Alice owns at index i, and bobSizes[j] is the number of candies in the candy box Bob owns at index j.

They wish to exchange exactly one candy box each so that, after the exchange, they both have the same total amount of candy.

Return an integer array containing two elements [aliceSizes[i], bobSizes[j]], where aliceSizes[i] is the size of the candy box Alice trades and bobSizes[j] is the size of the candy box Bob trades. If there are multiple valid answers, you may return any one of them.

Constraints:

  • 1≤1 \leq aliceSizes.length, bobSizes.length ≤104\leq 10^4

  • 1≤1 \leq aliceSizes[i], bobSizes[j] ≤105\leq 10^5

  • Alice and Bob have a different total number of candies.

  • There will be at least one valid answer for the given input.