451. Sort Characters By Frequency | 3 Ways | Sorting | Hash Table | Bucket Sort

  Рет қаралды 9,017

Aryan Mittal

Aryan Mittal

Күн бұрын

Пікірлер: 24
@6mahine_mein_google
@6mahine_mein_google 11 ай бұрын
Hats off to your consistency bro!! . Whenever i dont feel doing leetcode , ur video pops out in my feed outta nowhere
@dhruvrawatt9
@dhruvrawatt9 11 ай бұрын
same for me
@adityashekharsingh2669
@adityashekharsingh2669 9 ай бұрын
Love your explaining skills and hand movements ....helped me to get the patterns
@siddarthreddykoppera5930
@siddarthreddykoppera5930 11 ай бұрын
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
@anonymous10906
@anonymous10906 11 ай бұрын
he did not consider the time taken by append function
@halfthing2925
@halfthing2925 5 ай бұрын
The last approach was awesome 🔥
@mainakseal5027
@mainakseal5027 11 ай бұрын
isnt the last solution o(2*n) which is not better than o(n + klogk)
@aidennav7336
@aidennav7336 7 ай бұрын
nice explanation
@harshal8781
@harshal8781 11 ай бұрын
🤩
@learningmaths786
@learningmaths786 11 ай бұрын
good aryan
@Vaidehi_IIT
@Vaidehi_IIT 5 ай бұрын
u r grt
@Algorithmswithsubham
@Algorithmswithsubham 11 ай бұрын
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; }
@deepakbhallavi1612
@deepakbhallavi1612 11 ай бұрын
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_google
@6mahine_mein_google 11 ай бұрын
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
@agambedi4142
@agambedi4142 11 ай бұрын
I don't want to look bad but if you just use Hindi as well that'll be really good bro.
@sahilshrivastava6455
@sahilshrivastava6455 7 ай бұрын
bucket sort space complexity would be n^2
@kgjr.6224
@kgjr.6224 11 ай бұрын
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
@manoor0858
@manoor0858 8 күн бұрын
no lol repeat will take max amount of times as well
@kgjr.6224
@kgjr.6224 8 күн бұрын
​@@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
@manoor0858
@manoor0858 8 күн бұрын
@@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.6224
@kgjr.6224 8 күн бұрын
@@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.6224
@kgjr.6224 8 күн бұрын
@@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
@ChristianoSts
@ChristianoSts 8 ай бұрын
I failed my interview with this question
The Dark Side of .reserve()
18:50
Logan Smith
Рет қаралды 158 М.
Sort Characters By Frequency | Sorting | Lambda | Leetcode 451
17:24
codestorywithMIK
Рет қаралды 10 М.
Как Ходили родители в ШКОЛУ!
0:49
Family Box
Рет қаралды 2,3 МЛН
🎈🎈🎈😲 #tiktok #shorts
0:28
Byungari 병아리언니
Рет қаралды 4,5 МЛН
49. Group Anagrams | string | Hash Table
13:22
Aryan Mittal
Рет қаралды 6 М.
Sort Characters By Frequency - Leetcode 451 - Python
10:57
NeetCodeIO
Рет қаралды 20 М.
525. Contiguous Array | Prefix Sums | Hash Tables | 3 Approaches
18:30
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 147 М.
Transformers (how LLMs work) explained visually | DL5
27:14
3Blue1Brown
Рет қаралды 4,3 МЛН
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 100 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 161 М.
Как Ходили родители в ШКОЛУ!
0:49
Family Box
Рет қаралды 2,3 МЛН