On January 12, 2025, as we continue to refine our algorithms post-New Year, you are tasked with implementing a custom sorting algorithm with a twist. Given an array of integers and a separate array representing priority values, sort the input array such that:
Example:
arr = [5, 3, 9, 1, 3, 7, 1]
, priority = [3, 1]
[3, 3, 1, 1, 5, 7, 9]
Explanation:
3
and 1
are moved to the front in the order specified by the priority list.[5, 7, 9]
are sorted in ascending order and appended.Function Signature:
Implement a function that takes in two arrays and returns the sorted array based on the above rules.
Input:
arr
: An array of integers.priority
: An array of unique integers dictating the order of prioritized elements.Output:
Happy coding and enjoy the challenge!