solved on my own without even looking at the solution......... thanks bhaiya from the bottom of my heart........all credit goes to u your series literally boosted my confidence
@HelloWorldbyprince Жыл бұрын
Dil ❤️ se shukriya
@praneshchow3 ай бұрын
Thank you vie, Though It looks difficult, your explanation makes it easy.
@maniyadav32563 жыл бұрын
teen account se subscibe kiya hu, because you really deserve it ..................
@HelloWorldbyprince3 жыл бұрын
Waoo thanks for the support buddy
@vishaljain46423 жыл бұрын
Gazab Explanation 🔥🔥🔥
@shashwatdev23712 жыл бұрын
By using 2 ordered maps class Solution { public: vector frequencySort(vector& nums) { mapumap; map map_freq; vector final_vec; for(auto a:nums) { umap[a]++;//Saves numbers and their frequency } for(auto k:umap) { map_freq[k.second].push_back(k.first);// map like frequency->(vector containing numbers //having that frequency) } for(auto j:map_freq) { for(int i=j.second.size()-1;i>=0;i--)//reversing vector so that it can be sorted in descending order when frequency is same { for(int l=0;l
@HelloWorldbyprince2 жыл бұрын
good work
@pritamsarkar33713 жыл бұрын
also, you can try hashmap and minheap, which gives same ans with the same complexity
@masumali8356 Жыл бұрын
you are the best........masum.
@salmaniproductions1104 Жыл бұрын
Very well explained. Thank you bhaiyya
@khushipandey6172 Жыл бұрын
Similar problem on gfg gives error of time limit exceeded after passing 119 test case out of 240 . Problem :Sorting element of an array by frequency on gfg Can you provide other more optimized solution?
@vitaminprotein22172 жыл бұрын
heap sol unordered_mapumap; for(auto x:nums)umap[x]++; priority_queuemaxh; for(auto x:umap){ maxh.push({-x.second,x.first});//- lga ke daal denge usse lest freq wla max bn jyega aur pop krne ke time seedha result aa jyega } vectortemp; while(!maxh.empty()){ //to print acc to freq int freq = maxh.top().first; int element = maxh.top().second; for(int i=1;i
@HelloWorldbyprince2 жыл бұрын
Amazing yaar
@vishaljain46423 жыл бұрын
❤️❤️❤️❤️❤️
@lex-zt6uc2 жыл бұрын
thx bhaiya
@HelloWorldbyprince2 жыл бұрын
thanks bro
@maniyadav32563 жыл бұрын
WHEN THE DAYS ARE SORROW AND NIGHT ARE BITTER, THEN A JOURNEY SEEMS LIKE A BURDEN, DONT LOSS YOUR HOPE , AND KEEP SOME SOAP AS A TOOL TO CLEAN YOUR PATH OF HURDEL.
@HelloWorldbyprince3 жыл бұрын
😎😎 Yes
@SemicolonGuy3 жыл бұрын
Iski time complexity O (log n) kaise hui?
@Sonukumar-um3cs3 жыл бұрын
Sir bahut dino bad video aaya h Tree ke videos thoda jaldi jaldi dalna sir
@HelloWorldbyprince3 жыл бұрын
Ekdum sure
@rode_atharva5 ай бұрын
/*Example Comparisons During Sorting Initial Vector: nums = {4, 6, 2, 6, 4, 4, 3} Comparator Function: sort(nums.begin(), nums.end(), [&](int a, int b){ return umap[a] != umap[b] ? umap[a] < umap[b] : a > b; }); Comparing 4 and 6: umap[4] = 3 umap[6] = 2 Since umap[4] (3) is not equal to umap[6] (2), compare based on frequency: umap[4] < umap[6] evaluates to 3 < 2 which is false. So, 4 should come after 6. Second Comparison Comparing 6 and 2: umap[6] = 2 umap[2] = 1 Since umap[6] (2) is not equal to umap[2] (1), compare based on frequency: umap[6] < umap[2] evaluates to 2 < 1 which is false. So, 6 should come after 2. Third Comparison Comparing 2 and 6: umap[2] = 1 umap[6] = 2 Since umap[2] (1) is not equal to umap[6] (2), compare based on frequency: umap[2] < umap[6] evaluates to 1 < 2 which is true. So, 2 should come before 6. Fourth Comparison Comparing 6 and 4: umap[6] = 2 umap[4] = 3 Since umap[6] (2) is not equal to umap[4] (3), compare based on frequency: umap[6] < umap[4] evaluates to 2 < 3 which is true. So, 6 should come before 4. Fifth Comparison Comparing 4 and 4: umap[4] = 3 umap[4] = 3 Since umap[4] is equal to umap[4], compare based on value: 4 > 4 evaluates to false. So, the order remains unchanged. Final Sorted Vector After all necessary comparisons(SORT FUNCTION WILL SEE THIS, YOU MY FRIEND DONT CARE OF IT) and swaps, the final sorted vector nums is: {2, 3, 6, 6, 4, 4, 4} Summary of a and b in Comparisons During sorting, a and b are elements from the nums vector that are being compared. The custom comparator checks: If the frequencies of a and b are different (umap[a] != umap[b]), it returns true if a's frequency is less than b's frequency. If the frequencies are the same, it returns true if a is greater than b to ensure that larger elements come first for the same frequency. */
@gauravparasar45714 ай бұрын
costum comparator and lambda fn alg h ?
@starab69012 жыл бұрын
In place of lamda function can we use comparator
@HelloWorldbyprince2 жыл бұрын
yess
@VaibhavSutar-xm3cn4 ай бұрын
var frequencySort = function(nums) { let map = new Map() for(let i=0;ia[1]-b[1]) // console.log(sortedMap) let index = 0 for(let i=0;i0){ sortedMap[i][1] = sortedMap[i][1] -1 nums[index++] = sortedMap[i][0] } } return nums }; solved by own now will watch your tutorial
@samiulislamdurjoy3 жыл бұрын
7:22
@ogbuddha78352 жыл бұрын
Jun 19 2022, results are out of 6th sem yesterday. Placements are coming. Ask me after 1 year how am i and where am i
@HelloWorldbyprince2 жыл бұрын
Pakaa promise I will ask
@shubhambhatt2704 Жыл бұрын
@OGBuddhA Ha Bhai kidhar hai?
@ogbuddha7835 Жыл бұрын
@@shubhambhatt2704 placed in an international company. Good package 11lpa
@oqant0424 Жыл бұрын
17/18 done (11.12.22)
@HelloWorldbyprince Жыл бұрын
good
@satyamsrivastava18712 жыл бұрын
bhaiya maine asa socha pr problem aa rha class Solution { public: vector frequencySort(vector& nums) { vector ans; unordered_map um; for(auto x:nums) { um[x]++; } set s; for(auto x:um) { auto temp=x.second; s[temp]++; } for(auto x:s) { ans.push_back(x); } return ans; } };
@HelloWorldbyprince2 жыл бұрын
kya problem aa rha dry run karo koi ek example lekar samjh me aa jayega ki kya gaklti ho rha hai
@vishaljain46423 жыл бұрын
Bhaiya graph ki series kab ane wali he??
@HelloWorldbyprince3 жыл бұрын
Tree ke baad Tree ke baad maximum confidence aa jayega
@divyansh13912 жыл бұрын
bhaiya apne bass code kr diya hai...vhi to samjna hai vhi nhi btaye aap
@HelloWorldbyprince2 жыл бұрын
I will request u to please watch hashing playlist from starting buddy
@praveenanand56892 жыл бұрын
how to solve this problem without using lambda function
@hrithikraj65872 жыл бұрын
Also in java??
@HelloWorldbyprince2 жыл бұрын
sure but it will take some time
@udaymishra59163 жыл бұрын
Yaha ye kaise determine hua ki a is greater than b hi hai???
@HelloWorldbyprince3 жыл бұрын
Maine kaha tha, lambda function me ye maan ke chal rahe hai ki a pahle aayega b se
@KaifKhan-PizzaAndcode2 жыл бұрын
Bhaiya return wali line ek bar bta do smjh ni ayi Please Please Pleaseeeeeeeeeeeeeeeee.........
@HelloWorldbyprince2 жыл бұрын
kya nhi samjha ussme aap ye batao ek baar please Hashing starting se dekho aap please and ek baar dry run v karo mere code ko its your homework