Create an hash map and store frequencies of all array elements in it using element as key and frequency as value
unordered_map < int , int > freq ; for ( int i = 0 ; i < n ; i ++ ) freq [ arr [ i ] ] ++ ;