Fair Swap between Two Lists

Published by Evgeny SH in

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

Watch a quick demo on how Edabit works.