Advantage Shuffle

You are given two integer arrays nums1 and nums2 both of the same length. The advantage of nums1 with respect to nums2 is the number of indices i for which nums1[i] > nums2[i].

Return any permutation of nums1 that maximizes its advantage with respect to nums2.

Example 1
Inputnums1 = [2,7,11,15], nums2 = [1,10,4,11]
Output[2,11,7,15]
This permutation gives nums1 an advantage at three indices: 2 > 1, 11 > 10, and 15 > 11.
Example 2
Inputnums1 = [12,24,8,32], nums2 = [13,25,32,11]
Output[24,32,8,12]
This permutation maximizes the advantage by beating 13, 25, and 11 at three positions.

Constraints

  • 1 <= nums1.length <= 10^5
  • nums2.length == nums1.length
  • 0 <= nums1[i], nums2[i] <= 10^9

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate