Infosys
Jawaharlal Nehru Technological University, Kakinada 2021
C++ - Default language
My Stats
EXP gained
2735
Level
5 (Champion)
Community stats
Discussions
0
0
Know more
32
Total problems solved
24
Easy
8
Moderate
0
Hard
0
Ninja

Current streak:

0 days

Longest streak:

2 days

Less

More

Achievements
1
Ronin
Topics
Arrays
Discussions
c++ easy solution using unordered_map
Interview problems
``````vector<int> getFrequencies(vector<int>& v) {
unordered_map<int, int> m;
for(auto x:v){
m[x]++;
}
int minFreq, maxFreq, maxFreqMinEl, minFreqMinEl;
minFreq = maxFreqMinEl = minFreqMinEl = INT_MAX;
maxFreq = INT_MIN;

for(auto x: m){
int freq = x.second;
int el = x.first;
if(freq > maxFreq){
maxFreq = freq;
maxFreqMinEl = el;
}
if(freq == maxFreq){
maxFreqMinEl = min(maxFreqMinEl, el);
}

if(freq < minFreq){
minFreq = freq;
minFreqMinEl = el;
}
if(freq == minFreq){
minFreqMinEl = min(minFreqMinEl, el);
}
}
return {maxFreqMinEl, minFreqMinEl};
}``````
Guru Raja
Published On 01-Nov-2023
120 views
0 replies