Hats off to your consistency bro!! . Whenever i dont feel doing leetcode , ur video pops out in my feed outta nowhere
@dhruvrawatt911 ай бұрын
same for me
@adityashekharsingh26699 ай бұрын
Love your explaining skills and hand movements ....helped me to get the patterns
@siddarthreddykoppera593011 ай бұрын
In bucket sort I think time complexity is O(2N) , because we iterate over N characters and 0 to N frequencies so total N+N 2N... as you said N+k here k is always N so 2N however it's O(N) at the end
@anonymous1090611 ай бұрын
he did not consider the time taken by append function
@halfthing29255 ай бұрын
The last approach was awesome 🔥
@mainakseal502711 ай бұрын
isnt the last solution o(2*n) which is not better than o(n + klogk)
@aidennav73367 ай бұрын
nice explanation
@harshal878111 ай бұрын
🤩
@learningmaths78611 ай бұрын
good aryan
@Vaidehi_IIT5 ай бұрын
u r grt
@Algorithmswithsubham11 ай бұрын
why this is wrong ans string frequencySort(string s) { mapm; string ans=""; for(auto it:s)m[it]++; for(auto it :m){ char key=it.first; int val=it.second; while(val--){ ans+=key; } } return ans; }
@deepakbhallavi161211 ай бұрын
because, It is storing character in sorted order. Example:- string s = "abbbc" Then map will store 'a' -> 1 'b' -> 2 'c' -> 1 So we need to store data of map in additional data structure, which will store based on the frequencies of characters 1 -> 'a' 2 -> 'b' 1 -> 'c' And then sort the data structure and All set 😉
@6mahine_mein_google11 ай бұрын
class Solution { public: string frequencySort(string s) { vector freq(26, 0); int n = s.length(); for (char c : s) { freq[c - 'a']++; } vector bucket(n + 1); for (int i = 0; i < 26; i++) { char ch = 'a' + i; int f = freq[i]; if (f > 0) { bucket[f].push_back(ch); } } cout
@agambedi414211 ай бұрын
I don't want to look bad but if you just use Hindi as well that'll be really good bro.
@sahilshrivastava64557 ай бұрын
bucket sort space complexity would be n^2
@kgjr.622411 ай бұрын
Using this code the Generation of the ans String can be done in O(1) (not including the time complexity of mapping ie O(b)) class Solution { public String frequencySort(String s) { if (s == null || s.isEmpty()) return s; int[] freq=new int[128]; for(int i=0;i
@manoor08588 күн бұрын
no lol repeat will take max amount of times as well
@kgjr.62248 күн бұрын
@@manoor0858Yes but this can easily be replaced by a string builder. Also the internal methods are faster than the normal lopping. So in the actual test it performs better then expected
@manoor08588 күн бұрын
@@kgjr.6224 internal methods logic would be the same to insert elements how do u think the internal system insert n numbers , obv one by one ->o(n)
@kgjr.62248 күн бұрын
@@manoor0858 the logic is kind of same but those are well optimized and and when you like write a sort method and use the inbuilt method the inbuilt method performs better. Also try running this code it will result in i guess 90 to 100 % efficient.
@kgjr.62248 күн бұрын
@@manoor0858 because if you go with normal concatenation of string so it takes o(n,) it self so if the process repeat the concat will take around O(n^2) so it's better to use .repeat() or a stringbuilder