Quick actions

cmd+k|ctrl+k

Navigation

Languages

Frequency Sort

Snippet info

Language

Cpp

Visibility

public

Author

amangoyal1727

Created

2021-01-11T21:53:03Z

Updated

2021-01-11T21:53:03Z

#include <iostream>
#include <queue>
#include <map>
using namespace std;

int main() {
    
    int n;
    cin>>n;
    
    int A[n];
    for(int i=0; i<n ; i++){
        cin>>A[i];
    }
    
    map<int, int> mp;
    
    for(int i=0; i<n; i++){
        mp[A[i]]++;
    }
    
    priority_queue<pair<int,int>> maxh;
    
    for(auto i= mp.begin(); i!=mp.end(); i++){
        maxh.push({i->second , i->first});
    }
    
    while(maxh.size()>0){
        int f= maxh.top().first;
        int e = maxh.top().second;
        for(int i=0 ; i<f; i++)
            cout<<e<<" ";
        maxh.pop();
    }
}
INFO