← Back to challenges

Fair Swap between Two Lists

PythonHardalgorithmsconditionsloopsnumbers

Instructions

Find all swap pairs between two lists such that the sums of lists after the swap are equal. The input is two lists of integers, not necessarily of the same length. The output is a set of tuples {(num_from_l1, num_from_l2), ..}. If there is no pair found return an empty set.

Examples

fair_swap([1, 1], [2, 2]) ➞ {(1, 2)}

fair_swap([1, 2], [2, 3]) ➞ {(1, 2), (2, 3)}

fair_swap([2], [1, 3]) ➞ {(2, 3)}

fair_swap([2, 3, 4], [11, 4, 1]) ➞ set()

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.