2
def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]:3
# initialise a dictionary since we're going to want to count the occurences of each element in arr15
# this loop populates the dictionary with the number of occurences for each element7
if dic.get(elem) is None:10
dic[elem] = dic[elem] + 111
# initialise a new list to store the values which exist in both arr2 and arr113
# populate output with the elements multiplied by their occurences (e.g. [1]*2 = [1, 1])15
output += [elem] * dic[elem]16
# initialise a new list to store the elements which are in arr1 but not arr218
# populate extra_output with these elements multiplied by their occurences.19
# Note: set(arr1)-set(arr2) provides us with the set of numbers which exist in arr1 but not in arr220
for elem in set(arr1) - set(arr2):21
extra_output += [elem] * dic[elem]22
# return the first list and the sorted second list23
return output + sorted(extra_output)