Relative Sorting Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3 Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3
H
Harriet Muduwa
@Harriet Muduwa