Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Advantage Shuffle

XPChallenge Points: 20
levelLevel: Medium

You are given two integer arrays nums1 and nums2, both of equal length.
Your task is to rearrange (shuffle) the elements of nums1 so that it wins against nums2 as many times as possible.

A "win" is counted when at index i, nums1[i] > nums2[i].

Return any version of nums1 that achieves the highest number of such winning positions.

Example 1:

Input: nums1 = [4, 9, 1, 7] nums2 = [3, 8, 5, 6]

Output: [7, 9, 1, 4]

Explanation:

7 > 6, 9 > 8 (2 wins)

Example 2:

Input: nums1 = [5, 10, 15, 20] nums2 = [12, 6, 25, 3]

Output: [6, 10, 15, 20]

Explanation:

10 > 6, 20 > 3 (2 wins)

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result