Relative-sorting

easy
1. You will be given two Arrays with their lengths m and n. 2. You need to sort array 1 with respect to the order given in array 2. 3. For all the numbers not present in array 2, simply add them at the end of array 1's arrangement 3. Input and output is handled for you 4. It is a functional problem ,please do not modify main()

Input Format

Input is handled for you.

Output Format

Output is handled for you

Constraints

1 <= N,M  <= 10^6
 1 <= A1[], A2[] <= 10^6

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
8
9 6 7 4 7 4 9 3 
3
7 4 9
Output
7 7 4 4 9 9 3 6
Previous
Repeated Character
Next
Nearly Sorted Algorithm

Related Questions