Why my code is not printing correct output

#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main()
{
ll n,i,k,g;
cin>>n;
vectorv(n);vectora;
vectorw(n);
unordered_map<ll,ll>m;unordered_map<ll,ll>m2;
for(i=0;i<n;i++)
{
cin>>v[i];
m[v[i]]++;
}
for(i=0;i<n;i++)
{
cin>>w[i];
m2[w[i]]++;
}

for(i=0;i<n;i++)
{
g=min(m[v[i]],m2[v[i]]);
if(g!=0)
{
while(g){
a.push_back(v[i]);
gā€“;
}
}
}
sort(a.begin(),a.end());
cout<<"[";
for(i=0;i<a.size()-1;i++)
cout<<a[i]<<", ā€œ;
cout<<a[a.size()-1]<<ā€]";
return 0;

}

Hello @pradyumna_gupta please be in habbit of sharing code after saving on ide.codingblocks.com
please wait i am checking your code:

@pradyumna_gupta your code is not producing the correct ouput because when again in the array you will iterate and visit the same previous element then again you are printinh for that.
so when you have first visited once you have to reduce the frequency.

check this:
i have corrected your code:
https://ide.codingblocks.com/s/424485