For taking notes, What I did was note the important points on a Notebook earlier. But I wanted to access it anywhere so I started to make notes online (google doc etc) so that I can access it online from anywhere. Make. Google doc dedicated to every topic and keep the notes in those. Keep revisiting them time to time
I solved it like this. string frequencySort(string s) { string ans; int freq[128] = {0}; for(int i = 0; i < s.size(); i++){ freq[s[i]]++; } map m; for(int i = 0; i < 128; i++){ m[ freq[i] ] += string(freq[i], (char)i); } for(auto it = m.rbegin(); it != m.rend(); it++){ ans += it->second; } return ans; }
Hi Rajeev, let's look at an example to understand this. Suppose we have example : "tree" Now let's populate : vector vec; i = 0, 't', we don't have 't' populated in vector as of now. vec = { {'t', 1}} i = 1, 'r', we don't have 'r' populated in vector as of now. vec = { {'t', 1}, {'r', 1}} i = 2, 'e', we don't have 'e' populated in vector as of now. vec = { {'t', 1}, {'r', 1}, {'e', 1}} Now, for i = 3, 'e', we already have {'e', 1} in our vector So, take out frequency of 'e' already present in vector : i.e. freq = 1 int freq = 1 Now, we add 1 more to it, because we have got another 'e' at index = 3 and then insert it back to vec (updated value) vec = { {'t', 1}, {'r', 1}, {'e', 2}} Hope I was able to clear now. Thank you for watching
is solution me kya problem h? class Solution { public: string frequencySort(string s) { typedef pair P; vector arr(122); for (char& i : s) { int freq = arr[i].second; arr[i] = {i, freq + 1}; } auto lambda = [&](P &p1, P &p2) { return p1.second > p2.second; }; sort(arr.begin(), arr.end(), lambda); string ans = ""; for (int i = 0; i
@@harshasshet6755 Beta 9:00 minute se jo isne bataya hai voh code based hai (C++ language specific), isme conceptual kuch nhi hai. Real conceptual videos irrespective of lang. dekhne hai toh jaa kr Striver dekh munna.
aap jo story batate ho to lagta he bhai coding to me bhi kar sakta hu or bahot had tar to problme khud hi solve kar pata hu love you sir
I get relaxed when I see you already have a video on youtube for a problem.
lol same
same xD
You are genius, you don't know but you have explained it perfectly and far better than other TH-cam tutors.
Thank you so much!
Means a lot to me. Thank you so much 🙏😇
💯
Amazing brother....Keep uploading such wow content..
Thanks a lot Hrithik ❤️❤️❤️
Really thankyou bhaiya for making it so easy to understand and also learn new things about comparator from you
I am so glad to hear that Uday ❤️❤️❤️
Thanks a lot man. simple and crystal clear
Thanks, I solved it by myself still came here to learn something new and learnt something thanks.
So glad to know ❤️❤️🙏🙏
Always note down the things which you are learning in a note book, or note it down somewhere so that you can revisit them later
@@codestorywithMIK sir how to take notes and how to revise can you please share some insight regarding this.
@@Ankitkumar-fz3kc had the same doubt. @codestorywithmik pls share your inputs
For taking notes,
What I did was note the important points on a Notebook earlier.
But I wanted to access it anywhere so I started to make notes online (google doc etc) so that I can access it online from anywhere.
Make. Google doc dedicated to every topic and keep the notes in those.
Keep revisiting them time to time
Finally understood this concept. thanks a lot!
Nice explanation bhaiya
Keep uploading such amazing contents.
Awsm explanation !
I solved it like this.
string frequencySort(string s) {
string ans;
int freq[128] = {0};
for(int i = 0; i < s.size(); i++){
freq[s[i]]++;
}
map m;
for(int i = 0; i < 128; i++){
m[ freq[i] ] += string(freq[i], (char)i);
}
for(auto it = m.rbegin(); it != m.rend(); it++){
ans += it->second;
}
return ans;
}
Amazing brother...
Thanks a lot Varun ❤️❤️❤️
Thanks a lot bhaiya ❤❤
Please upload the PQ solution as well. I implemented this but I am unable to think in that direction
Me too.
It would be great to have a PQ solution as well for this from you @Interview_DS_Algo
Thanks in advance
Sure. I am on it.
Give me sometime. I will upload it today only.
Thanks again for your question and watching my videos
Uploaded the Heap(PQ) approach
Link :th-cam.com/video/HwCYa1_2vkU/w-d-xo.html
Thanks a lot@@codestorywithMIK
@@codestorywithMIK I was looking for this. Thank you
unordered_mapm;
for(auto x:s)
m[x]++;
sort(begin(s),end(s),[&](char a, char b){
return m[a]!=m[b]?m[a]>m[b]:a
is code ki space complexity or time complexity explain kr dijiye plz plz
vec[ch] or we have to take index
class Solution {
public String frequencySort(String str){
char[]s=str.toCharArray();
int[]freq=new int[128];
for(int i=0;i
Done ❤️
i m confused that how the pair get stored in vector can anyone help. line 9-11
Hi Rajeev, let's look at an example to understand this.
Suppose we have example : "tree"
Now let's populate : vector vec;
i = 0, 't', we don't have 't' populated in vector as of now.
vec = { {'t', 1}}
i = 1, 'r', we don't have 'r' populated in vector as of now.
vec = { {'t', 1}, {'r', 1}}
i = 2, 'e', we don't have 'e' populated in vector as of now.
vec = { {'t', 1}, {'r', 1}, {'e', 1}}
Now, for i = 3, 'e', we already have {'e', 1} in our vector
So, take out frequency of 'e' already present in vector : i.e. freq = 1
int freq = 1
Now, we add 1 more to it, because we have got another 'e' at index = 3 and then insert it back to vec (updated value)
vec = { {'t', 1}, {'r', 1}, {'e', 2}}
Hope I was able to clear now.
Thank you for watching
Yeah very helpful
Glad to know that Rajeev. Thanks
ordered map already sorted hota hai usse nhi kar sakte kya?
is solution me kya problem h?
class Solution {
public:
string frequencySort(string s) {
typedef pair P;
vector arr(122);
for (char& i : s) {
int freq = arr[i].second;
arr[i] = {i, freq + 1};
}
auto lambda = [&](P &p1, P &p2) { return p1.second > p2.second; };
sort(arr.begin(), arr.end(), lambda);
string ans = "";
for (int i = 0; i
Sir can you also code in java
bhaiua run time error aa rhaa 32 test case mai se 29 chle
My code seems to be working fine. Can you share your code ?
Mention in the video title only for C++ language, bcz Java valo ko toh kuch samjh hi nhi aya.
bro concept to same hai just language is diferent learn concept and for code ask chatgpt and all fine
@@harshasshet6755 Beta 9:00 minute se jo isne bataya hai voh code based hai (C++ language specific), isme conceptual kuch nhi hai.
Real conceptual videos irrespective of lang. dekhne hai toh jaa kr Striver dekh munna.