Sort Characters By Frequency | Heap | Leetcode 451

  Рет қаралды 5,128

codestorywithMIK

codestorywithMIK

Күн бұрын

This is the 2nd Video on our Heap playlist.
In this video we will try to solve a very famous and interesting Problem "Sort Characters By Frequency".
Share your learnings on LinkedIn, Twitter (X), Instagram, Facebook(Meta) with hashtag
hashtag#codestorywithmik & feel free to tag me.
We have already solved this Qn using Sorting of Vector in our Sorting Playlist.
Link for the Sorting Vector Approach - • Sort Characters By Fre...
Cpp-STL-Quick-Help - github.com/MAZ...
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : Sort Characters By Frequency
Company Tags : Google, Amazon, Oracle, Zoho, Zycus
My solutions on Github : github.com/MAZ...
Leetcode Link : leetcode.com/p...
My GitHub Repo for interview preparation : github.com/MAZ...
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish

Пікірлер: 40
@pranchalgupta2370
@pranchalgupta2370 Ай бұрын
You literally have to be the most underrated person teaching DSA for placements on youtube. You have no fucking idea how easy you make things for me. This content is good!!!
@adarshsrivastava3657
@adarshsrivastava3657 Жыл бұрын
guys follow up question for practice leetcode 1636
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so much for sharing ❤️😇
@engineeringsolved
@engineeringsolved 3 ай бұрын
instead of using comparator we can store it in {int, char} that way we don't need to use comparator
@abhishekverma7604
@abhishekverma7604 Жыл бұрын
string frequencySort(string s) { int n = s.length(); unordered_mapmp; for(auto x:s) { mp[x]++; } priority_queuepq; for(auto it:mp) { pq.push({it.second,it.first}); } string ans = ""; while(!pq.empty()) { auto ele = pq.top(); pq.pop(); for(int i = 0;i
@kamranwarsi12b22
@kamranwarsi12b22 11 ай бұрын
If we have pushed a pair of {frequency, char} like this , then we can avoid writing a comperator , because max heap will automatically sort itself according to the first value.
@technologicalvivek7510
@technologicalvivek7510 11 ай бұрын
min-heap priority_queue variable_name;
@alphadrones23
@alphadrones23 Жыл бұрын
Great... Ek request hai.. If you can start LLD and machine coding playlist
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks. Sure, will try to incorporate those soon
@sehajdeepsingh7427
@sehajdeepsingh7427 10 ай бұрын
I have a doubt.. why cant we just extract the string from map directly. We can store all the character's freq in map, and as map stores them in desc order, we can extract from it directly. I tried this but am getting wrong answer. Can anyone explain why is this happening?
@codestorywithMIK
@codestorywithMIK 10 ай бұрын
Ordered map stores things in a particular order. But unordered_map doesn’t store things in a particular order
@sehajdeepsingh7427
@sehajdeepsingh7427 10 ай бұрын
@@codestorywithMIK Alright Thanks !!
@arjunju469
@arjunju469 7 ай бұрын
class Solution { public: string frequencySort(string s) { unordered_mapmp; int n=s.size(); for(int i=0;i
@Sachin-2-9
@Sachin-2-9 7 ай бұрын
unordered_mapum; for(auto i:s) um[i]++; priority_queue pq; for(auto i:um) pq.push({i.second,i.first}); string ans=""; while(!pq.empty()){ pairtemp=pq.top(); pq.pop(); ans+=string(temp.first,temp.second); } return ans; short and easy👻👻
@technologicalvivek7510
@technologicalvivek7510 11 ай бұрын
Bhaiya aapne iss code me max heap use kiya na toh wo toh- priority_queuevar_name; hoga aapne jo defination di wo toh min-heap lag rahi.
@codestorywithMIK
@codestorywithMIK 11 ай бұрын
Min Heap : priority_queue pq; //creates min-heap priority_queue< pair, vector, greater > pq; //min_heap of pairs priority_queue< pair, vector, greater > pq; //min_heap of pairs
@codestorywithMIK
@codestorywithMIK 11 ай бұрын
priority_queue pq; //creates max-heap priority_queue pq; //creates max-heap
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
Bhai thanks yaar.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Glad I could help
@aws_handles
@aws_handles 7 ай бұрын
thanks a lot. I am learning heap now
@Chakss
@Chakss Жыл бұрын
More content like this please!🤍
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Sure thing 😇🙏
@saumyasrivastava5390
@saumyasrivastava5390 Жыл бұрын
Thank you so much!
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Glad I could help
@Momentsofmagic28
@Momentsofmagic28 7 ай бұрын
------>>👑
@technologicalvivek7510
@technologicalvivek7510 11 ай бұрын
Bhaiya aap itni aachi tarah se kaise code likh lete ho.Mein 350 leetcode questions solve kar chuka hu but kuch questions par hatak jata hu.Aur brushup kaise karo apni coding skills ko?
@DevOpskagyaan
@DevOpskagyaan 7 ай бұрын
Practice and more practice. That’s the only way
@khalidalam980
@khalidalam980 7 ай бұрын
Bhai CPU pe depend karta hai.
@technologicalvivek7510
@technologicalvivek7510 7 ай бұрын
@@khalidalam980 ho bhai mein engineer hu .meko bhi pta hai wo toh .Time complexity cpu pe bhi or code kitna complex hai kitne functions call,loop hai uspe depend karta hai.Yaha conceptual learning ki baat ho rahi bhai aap kaha cpu le aaye beech me😂
@codestorywithMIK
@codestorywithMIK 7 ай бұрын
Hi there, As per me the best way to brush up/revise the concepts is to pick topic wise first. This is just to understand and give a bird view on what those topics are etc. For every topic, when you are done with bird view (revision), solve 2-3 problems for revision and usage of the topic. Once done, then the ultimate goal MUST be - “Am i able to solve randomly any problem without knowing which topic it belongs to” For this you can choose random problems Give contests which is one of the best ways to get better in DSA. if you couldn’t solve the contest problems during the contest, it’s totally fine, don’t stress and upsolve them and understand the core thing about the problem which you missed .
@technologicalvivek7510
@technologicalvivek7510 7 ай бұрын
@@codestorywithMIK ok thank you bhaiya.You will be happy to know that my brother He is currently studying in MANIT bhopal second sem .He has learned coding from you and all other youtube channels and within 3 months after completion of their 12th class during the vacation he learned dsa and he has solved 500+problem on leetcode,1800+ rating on leetcode and 3* star coder on codechef
The joker favorite#joker  #shorts
00:15
Untitled Joker
Рет қаралды 30 МЛН
An Unknown Ending💪
00:49
ISSEI / いっせい
Рет қаралды 56 МЛН
Пришёл к другу на ночёвку 😂
01:00
Cadrol&Fatich
Рет қаралды 11 МЛН
Life hack 😂 Watermelon magic box! #shorts by Leisi Crazy
00:17
Leisi Crazy
Рет қаралды 11 МЛН
Sort Characters By Frequency | Sorting | Lambda | Leetcode 451
17:24
codestorywithMIK
Рет қаралды 8 М.
Sort Characters By Frequency - Leetcode 451 - Python
10:57
NeetCodeIO
Рет қаралды 17 М.
Is Computer Science still worth it?
20:08
NeetCodeIO
Рет қаралды 348 М.
451. Sort Characters By Frequency || Leetcode || C++ || Hindi
8:54
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 396 М.
The joker favorite#joker  #shorts
00:15
Untitled Joker
Рет қаралды 30 МЛН