Thanks alot! Even after watching some resources about bucket sort, I was unable to wrap up my mind around it but you made it easy for me and finally solved daily problem on leetcode with bucket sort as you suggested to do at the end of your video.
bhai if you want to make the dp series a paid one, I'll be happy to join. I felt really bad yesterday after seeing your shorts. If it helps you and the channel in any way, please make the dp series a paid course. You deserve more subscribers and all the love ❤💙
damn the second approach is very unique i solve lot of question but i am not able think this way i learned the new technique (bucket sort) thanks bhiya ....
great sir , maine bhi yahi socha priority quey and woh reverse map ka , reverese map wale me tle arha tha kafi time lagaya thik nhi hua and yeh priortiy queu wale me mai woh class comparator ka soch rha tha but usme bhi thik nhi hua ab apka video tdekha toh galti samjh ayi and thanx sir time compleixty discussion ke liye bhi yeh sabse best hai ,
Mik , In one of previous lectures you taught how to make a customize seperator acc. to the problem so i used that still did this with max heap making lambda as my custom operator thank you🎉
Hi MIK, thank you for the details explanations for all the different problems. I am now one of your follower :) I have a small doubts, at time 13:29, the PriorityQueue add operations will happen n times or k times. because irrespective of the k, we are adding all the items.
thankyou for kind help we can solve it in quite simple way also this is how C++ class Solution { public: vector topKFrequent(vector& nums, int k) { unordered_mapmp; vectorans; priority_queuepq; for(auto i:nums){ mp[i]++; } for(auto &it:mp){ pq.push({it.second,it.first}); } while(k--){ int temp=pq.top().second; pq.pop(); ans.push_back(temp); } return ans; } };
Bro I need a help. I have written a code using map but it passes some test case.Please help me to find out what are the mistake I do in this code. class Solution { public: vector topKFrequent(vector& nums, int k) { mapmpp; vectorans; for(int i=0;i=k) { ans.push_back(it.first); } } return ans; } };
why are you checking the freq of the element with k? k is just no. of terms required. and it.second is the freq of each element that appeared in nums. Instead make a max-heap that stores all the freq along with the value, and extract top k elements into your answer vector.
#5:58 at this point i understood why min heap is used.............earlier i solved this via max heap..........and i was confused which one to use
Awesome ❤️❤️❤️
Your explantion is very clear, after Striver i only follow you.
please tell me what tool are you using from these drawing, i want to practice on my ipad
Thanks alot! Even after watching some resources about bucket sort, I was unable to wrap up my mind around it but you made it easy for me and finally solved daily problem on leetcode with bucket sort as you suggested to do at the end of your video.
bhai if you want to make the dp series a paid one, I'll be happy to join. I felt really bad yesterday after seeing your shorts. If it helps you and the channel in any way, please make the dp series a paid course. You deserve more subscribers and all the love ❤💙
I am in too. This guys never even asks us to like , share or subscribe.
He deserves it
That's true. He deserves. I don't know how he manages full time job and making these detailed videos
I agree also. He deserves more...
So true. He deserves it
True
NICE SUPER EXCELLENT MOTIVATED
damn the second approach is very unique i solve lot of question but i am not able think this way i learned the new technique (bucket sort) thanks bhiya ....
bhaiya aap samjate bahut aacha ho.Tough ko bhi easy kar dete ho.Thank you for this lecture.
Thank you so much 😇❤️
cristal clear explanation
Java Solution:
Priority Queue:
class Pair{
int first;
int second;
public Pair(int first,int second){
this.first = first;
this.second = second;
}
}
class Solution {
public int[] topKFrequent(int[] nums, int k) {
Map mp = new HashMap();
for(int num : nums) {
mp.put(num, mp.getOrDefault(num,0)+1);
}
PriorityQueue pq = new PriorityQueue((x,y) -> x.first - y.first);
for(var entry : mp.entrySet()) {
int value = entry.getKey();
int freq = entry.getValue();
pq.offer(new Pair(freq,value));
if(pq.size() > k){
pq.poll();
}
}
int[] result = new int[k];
for(int i=0; i= 0; i--){
if(bucket[i] != null){
for(int v : bucket[i]){
res[index++] = v;
if(index == k) return res;
}
}
}
return res;
}
}
great sir , maine bhi yahi socha priority quey and woh reverse map ka , reverese map wale me tle arha tha kafi time lagaya thik nhi hua and yeh priortiy queu wale me mai woh class comparator ka soch rha tha but usme bhi thik nhi hua ab apka video tdekha toh galti samjh ayi
and thanx sir time compleixty discussion ke liye bhi yeh sabse best hai ,
very nyc explanation sir hats off
Second solution is new for me. ThankYou
Thank you for watching ❤️❤️
Great approach !!
I knew this guys will be adding extra more approach. Thanks for the bucket sort solution
You deserve subs more bhaiyya 😢❤
Big Fan of your hardwork and consistency.
It means a lot to me. Thank you for your kind words ❤️❤️❤️
Last approach was Lit🔥.
❤️❤️❤️ thank you Arjun
Mik , In one of previous lectures you taught how to make a customize seperator acc. to the problem so i used that still did this with max heap making lambda as my custom operator
thank you🎉
That’s awesome ❤️❤️❤️
14:03 ::: approach 2 (Bucket sort)
Great Video ❤
Hi MIK, thank you for the details explanations for all the different problems. I am now one of your follower :)
I have a small doubts, at time 13:29, the PriorityQueue add operations will happen n times or k times. because irrespective of the k, we are adding all the items.
Thank You bro. One request please make a detail video on comparator in c++
Sure thing ❤️
Thanks for this detailed soln.😇
Thank you for watching Alok ❤️
best channel
// Brute force solution
class Solution {
public:
static bool cmp( const pair& a, const pair& b) {
return a.second > b.second;
}
vector topKFrequent(vector& nums, int k) {
mapmp;
for(auto x:nums)
{
mp[x]++;
}
vectorv(mp.begin() , mp.end());
sort(v.begin(), v.end() ,cmp );
vectorans;
for(int i=0;i
Thanks a lot for sharing ❤️❤️
thankyou for kind help
we can solve it in quite simple way also this is how
C++
class Solution {
public:
vector topKFrequent(vector& nums, int k) {
unordered_mapmp;
vectorans;
priority_queuepq;
for(auto i:nums){
mp[i]++;
}
for(auto &it:mp){
pq.push({it.second,it.first});
}
while(k--){
int temp=pq.top().second;
pq.pop();
ans.push_back(temp);
}
return ans;
}
};
Bro ur there on codeforces and codechef?
Can you make the playlist specific to the companies? Like for questions which was asked in Microsoft would be gathered in one playlist If possible.
thanks bhaiya
Mik, please use a mic. Voice is low without head phones.
Will soon buy a mic for fixing this issue.
Thanks a lot for the feedback
ughh, incase of higher size of the nums array, soln 2 will fail,right(since it will lead to memory limit exceeded)?
No , it wont max value is just 10000 so will be the frequency if all digits are same
make a video of k closet point to origin
bucket sort mei quadratic time complexity kyu nhi hai koi explain kr skta hai mujhe. mai humesha aisi questioni mei atakta hu
16:40 If we sort that, it will be a massacre. the track of the index will be lost. ( just sharing an insight for a noob like me).
Bro I need a help. I have written a code using map but it passes some test case.Please help me to find out what are the mistake I do in this code.
class Solution {
public:
vector topKFrequent(vector& nums, int k) {
mapmpp;
vectorans;
for(int i=0;i=k)
{
ans.push_back(it.first);
}
}
return ans;
}
};
why are you checking the freq of the element with k?
k is just no. of terms required. and it.second is the freq of each element that appeared in nums.
Instead make a max-heap that stores all the freq along with the value, and extract top k elements into your answer vector.
Bhai aapka toh mail bhar jaata hoga YT comments se
Yes 😅
This compliment from my side ❤ Thanks man@@codestorywithMIK
CAN ANYONE TELL ME THE TC OF THIS CODE ?
HashMapmap=new HashMap();
if(nums.length == k) return nums;
for(int i=0;imap.get(a)-map.get(b));
int res[]=new int[k];
for(int z:map.keySet()){
pq.add(z);
if(pq.size()>k)pq.poll();
}
int x=0;
while(!pq.isEmpty())res[x++]=pq.poll();
return res;
Is it also O(NLOGK) ??
Yes. It’s nlogk
Nlogk