Problem in Intersection of Arrays

The code is running fine but the three test cases are not being passed.
Question
Take as input N, the size of array. Take N more inputs and store that in an array. Take N more inputs and store that in another array. Write a function which gives the intersection of two arrays in an ArrayList of integers and Print the ArrayList.

Constraints:
Length of Arrays should be between 1 to 1000.

Sample Input:
7
1 2 3 1 2 4 1
2 1 3 1 5 2 2
Sample Output:
[1, 1, 2, 2, 3]
Explanation:
Check which integer is present in both the arrays and add them in an Arraylist .Print ArrayList as the ans.
Code

Your code is giving compilation errors, please check and code it again.
I am giving you the hint to approach the problem:

  1. Maintain a hash map with key as the element of array and value as the frequency of that element in the array.
    Push all the elements of 1st array in the hash map
  2. Iterate through the 2nd array, if an element is present in the hashmap then push it in an output array/vector.
    For these steps, code would be something like this:
    for(int i=0;i<n;i++)
    {
    cin>>arr1[i];
    hashmap[arr1[i]]++;
    }
    for(int i=0;i<n;i++)
    {
    cin>>arr2[i];
    if(hashmap.count(arr2[i])){
    if(hashmap[arr2[i]]>0)
    v.push_back(arr2[i]);
    hashmap[arr2[i]]–;
    }
  3. After that sort the Output vector and print it.

Despite using the hashmap and maintaining the frequency of each element and sorting the output array, the test case is not being passed
Code https://ide.codingblocks.com/s/118313

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.