Hashing - TOP K MOST FREQUENT ELEMENTS | C++ Placement Course | Lecture 32.7

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

This is search of first K distinct elements in the array and NOT Top K frequent elements.

vineetmidha
Автор

honestly speaking bhaiya, ap accha explain nhi krte.

abhaykaushik
Автор

Actual code of "Top K frequent elements in array"

bool compare(pair<int, int> &p1, pair<int, int> &p2)
{
if (p1.second == p2.second)
{
return (p1.first > p2.first);
}
return (p1.second > p2.second);
}
class Solution
{
public:
vector<int> topK(vector<int>& arr, int k) {
// Code here
vector<int> ans;
int n = arr.size();
if (k > n)
return ans;
unordered_map <int, int> m;
int s;
for (int i = 0; i < n; i++)
{
m[arr[i]]++;
}
arr.clear();
s = m.size();
if (k > s)
return ans;
vector<pair<int, int>> v;
unordered_map <int, int> :: iterator it;
for (it = m.begin(); it != m.end(); it++)
{
v.push_back(*it);
}
m.clear();
sort(v.begin(), v.end(), compare);
for (int i = 0; i < k; i++)
{
ans.push_back(v[i].first);
}
return ans;

}
};

gauravupreti
Автор

Aman bhaiya please launch apptitude series for placement.... So that we can solve one question in one minute....

munmunsahu
Автор

thankyou for all the videos!! jitna bhi appreciate kre ...kum he hai

atin_jagotra
Автор

Me waiting for that divine personality to come and bless my parents 😌

sanidhyasharma
Автор

कोरोना के कारण जितने लोगो की मौत हुई है
भगवान से विनती करूँगा कि उनकी आत्मा को शांति मिले जय हिन्द
stay home Stay safe

gautam_editsz
Автор

Description me video link dal dia kijie.

riyabharti
Автор

Yaar question top k most frequent elements ka log first k elements ka karwaa rhe... question to dekh liya Karo code karne se pehle....quantity k chakkar mein ab quality ki maa behen ek kar rhe ho

thatnaman
Автор

Please upload all videos at a single time you can upload all .

ritik
Автор

Aman Bhaiya, waiting for more videos on the web development course?

sahilsaini
Автор

unordered_map<int, int>mp;
priority_queue <pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>MIN;
vector<int>v={1, 1, 1, 3, 2, 2, 4, 4, 4};
int i, n=v.size();
for(i=0;i<n;i++)
{
mp[v[i]]++;
}
for(auto i=mp.begin();i!=mp.end();i++)
{
MIN.push({i->second, i->first});
if(MIN.size()>2)
MIN.pop();
}
while(MIN.size()>0)
{
cout<<MIN.top().second;
MIN.pop();
}



simple sa code tha bc pata nahi kya khani likh diya .

shreyankshrestha
Автор

Continue this series add more advance Concepts

mohitjoc
Автор

hashing to tabhi he khelata he jab hum unordered_map use kare....

Apna_dhamaka_
Автор

Sir pls upload video on web development too.. I really wanna study futher in that course

shreyashbhandari
Автор

Web development ka video upload kaeiye bhaiya

siddharthsinghh
Автор

Bhai please help mujse VS code mie apne files delete ho gayi. Ab unhe restore kaise karu🙏🙏🙏🙏🙇🙇

RohanSharma-jhny
Автор

very poor explaination continued in hashing after heap

ankitmahapatra
Автор

Bhiyaa java ka placement courses half m q leave....kiye

Hidden..
Автор

Fact: If you can understand the worst explication (as verbally expressed by the viewers) the you can learn anything expeditious(in time) as compared to others.

anirudhrajebhosle