Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Custom Priority Sorting of Elements

XPChallenge Points: 10
levelLevel: Easy

You are given two integer arrays arr1 and arr2.
All elements of arr2 are distinct and are guaranteed to exist in arr1.

Rearrange arr1 so that:

  • The elements appear in the same sequence as they appear in arr2.

  • Any values in arr1 that are not found in arr2 must be placed at the end, sorted in non-decreasing order.

Example 1:

Input: arr1 = [7,5,7,3,9,5,1] arr2 = [5,7,1]

Output: [5,5,7,7,1,3,9]

Example 2:

Input: arr1 = [4,11,4,8,6,8,3] arr2 = [8,4]

Output:

Explanation:

[8,8,4,4,3,6,11]

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