Group Anagrams (LeetCode 49) | Full solution with 2 methods and examples | Study Algorithms

  Рет қаралды 33,703

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 59
@dhavalchaudhary1786
@dhavalchaudhary1786 7 ай бұрын
I generally not hit like on youtube videos, but this guy nailed it. Thanks for your community contribution NIkhil.
@vikashsharma9678
@vikashsharma9678 3 ай бұрын
sir you explaination to any algorithm is the best explanation i had ever seen ...only your explanation is enough to solve the problem no need to see the code
@devprakash5320
@devprakash5320 3 жыл бұрын
loved your explanation . But 1 thing I would like to correct . The time complexity of method 1 will be O(n k log k ) , where k is the length of the string , n is total strings . This is because sorting a string would take (k log k ) . Any way awesome explanation . thanks
@WhosShamouz
@WhosShamouz Жыл бұрын
I was missing ONE idea and it popped in my head when I saw your first method, amazing explanation!
@amitbhattacharya356
@amitbhattacharya356 2 жыл бұрын
I got really surprised by so a vivid and clear explanation. I appreciate your efforts.
@nikoo28
@nikoo28 2 жыл бұрын
Glad I could help you out 😄
@ricardohernandezmendez4207
@ricardohernandezmendez4207 6 ай бұрын
At the beginning it was difficult to find out how to solve this problem, but with this explanation it make it easy to solve it. Thank.
@plutomessi21
@plutomessi21 Жыл бұрын
Dhanyavad bhaiya, you are the best teacher I have seen on youtube😭
@nikoo28
@nikoo28 Жыл бұрын
So nice of you
@akashddeepchitransh4537
@akashddeepchitransh4537 22 күн бұрын
Hey, you are super underrated, I didn't know about you channel but now I know and will be utilizing it in my preparation.
@mazthespaz1
@mazthespaz1 5 ай бұрын
i'm new to python and this was my solution def smash(str): tmp = 1 orda = ord('A')-1 ls = len(str) for i in range( ls ): tmp = tmp * (ord(str[i]) - orda) return tmp def groop(wordlist): grope = {} for word in wordlist: hashy = smash(word) if hashy not in grope: grope[hashy] = [] grope[hashy].append(word) return [val for val in grope.values()] if __name__ == '__main__': # arr = [ 'cat','tea','tan','ate','nat','bat' ] arr = [ 'eat','cars','tea','scar','a','listen','silent'] print (groop(arr))
@mazthespaz1
@mazthespaz1 5 ай бұрын
this solution worked in codewars but not leetcode. i need to refine the smash function to prevent duplicate hashes
@akshanshsharma8157
@akshanshsharma8157 8 ай бұрын
In the sorting way, the time complexity is not O(nlogk) but rather O(n.klogk)
@Donkle365
@Donkle365 2 жыл бұрын
Hey, I found this video trough the article and thank you for all the work, it really helped me. The solution of method 2 at line 34 has a mistake: "freq++;", you can't ++ an array, so we need to do freq[c - 'a']++ :)
@Vishal-8995
@Vishal-8995 11 ай бұрын
Premium Explanation
@nikoo28
@nikoo28 11 ай бұрын
🤘🏻
@shaileshsathe9779
@shaileshsathe9779 2 жыл бұрын
Very well explained the techniques, code and dry-run. Great work Nikhil.
@shaileshsathe9779
@shaileshsathe9779 2 жыл бұрын
I don't know why, I ran both techniques sorting and frequency but sorting is showing less time than frequency method. sorting => 15ms frequency = 29ms. I believe its random.
@aryamiraozdemir
@aryamiraozdemir Жыл бұрын
@@shaileshsathe9779 I'm not sure but I think it might be because frequency string has to be sorted so it takes even longer to count everything and sort the letters alphabetically
@ramsidh2218
@ramsidh2218 2 жыл бұрын
great explanation with animation step by step
@shahbazhussain2128
@shahbazhussain2128 Ай бұрын
If I use sorting logic will be my solution wrong? I am facing difficulty in understanding the HasMap and Frequency Concept.
@yusufnurwahid898
@yusufnurwahid898 5 ай бұрын
Very clear explanation! Keep up!!! 👍🏻
@ElinaAdibi-b1t
@ElinaAdibi-b1t 2 ай бұрын
Thank you, you explained it very well!
@lofiboy7866
@lofiboy7866 Ай бұрын
We need to write getfrequency string string method also sep?
@TBVSAITEJA21BCE840
@TBVSAITEJA21BCE840 12 күн бұрын
obviously
@hersheynohara5887
@hersheynohara5887 Жыл бұрын
That's an amazing explanation! 👏👏
@RohitSharma-q8j1p
@RohitSharma-q8j1p 7 ай бұрын
great video and best ever explaination ever
@abinashpanda393
@abinashpanda393 11 ай бұрын
This might not pass all test cases, you have to add a delimiter like '#' while concatenating numbers in freq variable.
@nikoo28
@nikoo28 10 ай бұрын
passes all cases on Leetcode as per the problem constraints. If you have different strings patterns, it might need a little tweaking.
@abinashpanda393
@abinashpanda393 10 ай бұрын
​@@nikoo28 You are right for ["bdddddddddd","bbbbbbbbbbc"] this will not going to pass. Probably new test cases have been added. Thank you for your response. Your tutorials are really helpful.
@cricworld5806
@cricworld5806 2 жыл бұрын
sir awesome explanation ...................
@edd_gos
@edd_gos 3 ай бұрын
bro, thank you for the video. it was very usefull (like all your videos)
@yfchina143
@yfchina143 8 ай бұрын
this there any better way for a frequency string algothrim?
@zanefalcao3230
@zanefalcao3230 3 ай бұрын
very nice explanation
@jst8922
@jst8922 11 ай бұрын
8:14 should be "nat", not sorted string "ant". Otherwise your tutorials are the best regarding leetcode problems, because you explain with examples what should the code do.
@cuteangel1726
@cuteangel1726 Жыл бұрын
Appreciate your effort !!!
@sayanmanna2511
@sayanmanna2511 11 ай бұрын
But why light theme?? I am blind now..
@nikoo28
@nikoo28 11 ай бұрын
Light is easier for diagrams and animations. Will keep using light theme.
@hazerasarker2442
@hazerasarker2442 Жыл бұрын
Thank you Nikhil :D
@devansh_4u
@devansh_4u Жыл бұрын
beats 30% java codes, wonder what could be a better solution!
@nikoo28
@nikoo28 Жыл бұрын
If you are concerned about having an overall faster solution, C++ should be the preferred language. Even with Java you can leverage some sort of caching and pre-processing of some results to obtain faster solutions. Generally not needed.
@devansh_4u
@devansh_4u Жыл бұрын
@@nikoo28 thanks sir
@mujeebbridgetown
@mujeebbridgetown 2 жыл бұрын
Nice explanation
@sysybaba420
@sysybaba420 Жыл бұрын
Great video as usual thanks for this! PS its not pronounced vo-i-la but just vo-la, hope this helps!
@abhishekshankar6305
@abhishekshankar6305 Жыл бұрын
you are the best
@yogeshganpule2695
@yogeshganpule2695 4 ай бұрын
tried watching but you just explained what the code does and its too confusing for me to undertsand what for each freq [c -'a']++; Does
@nikoo28
@nikoo28 4 ай бұрын
c is the actual character…let us say it is character ‘k’ And we do c - ‘a’ What happens internally is both are converted to ascii Small ‘a’ has ascii 97 The character ‘k’ has ascii 107 So when you do c - ‘a’ we get 107-97 = 10 That means freq[10] This represents 11th character as array is 0 based indexing Means we are referring to frequency of 11th character in the English alphabet which is letter ‘k’
@yogeshganpule2695
@yogeshganpule2695 4 ай бұрын
@@nikoo28 Thanks .
@MahiM-ze4hm
@MahiM-ze4hm 3 ай бұрын
Awesome 👏✊👍
@studies3943
@studies3943 3 ай бұрын
your accent is sweet
@fourieruddin871
@fourieruddin871 Жыл бұрын
Best
@himadripaul7332
@himadripaul7332 2 жыл бұрын
Excellent ... But disheartened to see less subscribers ... ☹️😑🙂
@nikoo28
@nikoo28 2 жыл бұрын
Yea…I don’t understand why my channel does not show up in results and suggestions. I have been doing everything possible: video descriptions, links etc.
@shaileshsathe9779
@shaileshsathe9779 2 жыл бұрын
@@nikoo28 You can add keywords like Leetcode, Anagram, Interview Prep just like you added for String.Maybe it will work
@boomshakalaka8567
@boomshakalaka8567 2 жыл бұрын
There's nothing correct about this video. Lol. Indian programmers lulz
@nikoo28
@nikoo28 2 жыл бұрын
did you find some problem in the explanation or the method? Always up for improvement...
@Sarvy001
@Sarvy001 2 жыл бұрын
@@nikoo28 I have found another solution here. Not explained in detail as you have done, but this one has less lines of code. kzbin.info/www/bejne/nHKtonSkerykZtE&ab_channel=ThatIndianCoder
@Nishi-Tiwari
@Nishi-Tiwari Жыл бұрын
@@nikoo28 You are best!
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
Group Anagrams - Leetcode 49 - Hashmaps & Sets (Python)
7:28
Greg Hogg
Рет қаралды 14 М.
Group Anagrams - Categorize Strings by Count - Leetcode 49
8:12
Group Anagrams LeetCode Java ( Most Important )
9:56
Engineering Digest
Рет қаралды 2,1 М.
Group Anagrams - LeetCode 49 - Python
16:54
DEEPTI TALESRA
Рет қаралды 4 М.
Group anagrams | Leetcode #49
13:50
Techdose
Рет қаралды 87 М.
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН