Given two arrays arr1 and arr2, sort the elements of arr1 such that:
arr2 come first, ordered according to their position in arr2arr2 are placed at the end, sorted in ascending orderEach element in arr2 is distinct. Every element in arr2 is also present in arr1.
Return the sorted array.
arr1 = [2, 3, 1, 3, 2, 4, 6, 7, 9, 2, 19], arr2 = [2, 1, 4, 3, 9, 6][2, 2, 2, 1, 4, 3, 3, 9, 6, 7, 19]arr1 = [28, 6, 22, 8, 44, 17], arr2 = [22, 28, 8, 6][22, 28, 8, 6, 17, 44]arr1 = [1, 2, 3], arr2 = [3, 2, 1][3, 2, 1]1 <= arr1.length <= 10000 <= arr1[i] <= 10001 <= arr2.length <= arr1.lengthAll elements of arr2 are distinctEach element of arr2 is present in arr1Run your code to see results
Use Cmd+Enter to run