← Back to challenges

Shuffle the List to Maximize Count of Greater Values

PythonHardalgorithmsarrayslogicnumbers

Instructions

The function is given two lists of equal length a, b. Shuffle the first list a such that the count of a[i] > b[i] for 0 <= i < len_a is at its maximum. Return the shuffled list a.

Examples

shuffle_a([3, 5], [4, 2]) ➞ [5, 3]

shuffle_a([2, 7, 11, 15], [1, 10, 4, 11]) ➞ [2, 11, 7, 15]

shuffle_a([12, 24, 8, 32], [13, 25, 32, 11]) ➞ [24, 32, 8, 12]

Notes

Multiple solutions are possible. That is why there is a helper function in the Tests window that counts number of a[i] greater than b[i] to allow different outcomes from the solution.

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