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

Поделиться
HTML-код
  • Опубликовано: 17 сен 2024

Комментарии • 54

  • @devprakash5320
    @devprakash5320 3 года назад +15

    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

  • @dhavalchaudhary1786
    @dhavalchaudhary1786 5 месяцев назад +6

    I generally not hit like on youtube videos, but this guy nailed it. Thanks for your community contribution NIkhil.

  • @WhosShamouz
    @WhosShamouz 11 месяцев назад +5

    I was missing ONE idea and it popped in my head when I saw your first method, amazing explanation!

  • @amitbhattacharya356
    @amitbhattacharya356 2 года назад +8

    I got really surprised by so a vivid and clear explanation. I appreciate your efforts.

    • @nikoo28
      @nikoo28  2 года назад

      Glad I could help you out 😄

  • @vikashsharma9678
    @vikashsharma9678 Месяц назад +1

    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

  • @plutomessi21
    @plutomessi21 Год назад +4

    Dhanyavad bhaiya, you are the best teacher I have seen on youtube😭

    • @nikoo28
      @nikoo28  Год назад +1

      So nice of you

  • @yusufnurwahid898
    @yusufnurwahid898 3 месяца назад +1

    Very clear explanation! Keep up!!! 👍🏻

  • @ricardohernandezmendez4207
    @ricardohernandezmendez4207 4 месяца назад

    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.

  • @mazthespaz1
    @mazthespaz1 3 месяца назад +1

    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 3 месяца назад

      this solution worked in codewars but not leetcode. i need to refine the smash function to prevent duplicate hashes

  • @akshanshsharma8157
    @akshanshsharma8157 6 месяцев назад +2

    In the sorting way, the time complexity is not O(nlogk) but rather O(n.klogk)

  • @zanefalcao3230
    @zanefalcao3230 Месяц назад

    very nice explanation

  • @Donkle365
    @Donkle365 2 года назад +1

    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']++ :)

  • @edd_gos
    @edd_gos 20 дней назад

    bro, thank you for the video. it was very usefull (like all your videos)

  • @RohitSharma-q8j1p
    @RohitSharma-q8j1p 4 месяца назад

    great video and best ever explaination ever

  • @MahiM-ze4hm
    @MahiM-ze4hm 29 дней назад

    Awesome 👏✊👍

  • @ramsidh2218
    @ramsidh2218 2 года назад

    great explanation with animation step by step

  • @hersheynohara5887
    @hersheynohara5887 Год назад

    That's an amazing explanation! 👏👏

  • @shaileshsathe9779
    @shaileshsathe9779 Год назад

    Very well explained the techniques, code and dry-run. Great work Nikhil.

    • @shaileshsathe9779
      @shaileshsathe9779 Год назад

      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

  • @Vishal-8995
    @Vishal-8995 9 месяцев назад +1

    Premium Explanation

    • @nikoo28
      @nikoo28  8 месяцев назад

      🤘🏻

  • @cuteangel1726
    @cuteangel1726 Год назад

    Appreciate your effort !!!

  • @sysybaba420
    @sysybaba420 10 месяцев назад +1

    Great video as usual thanks for this! PS its not pronounced vo-i-la but just vo-la, hope this helps!

  • @cricworld5806
    @cricworld5806 Год назад

    sir awesome explanation ...................

  • @yfchina143
    @yfchina143 6 месяцев назад

    this there any better way for a frequency string algothrim?

  • @hazerasarker2442
    @hazerasarker2442 11 месяцев назад

    Thank you Nikhil :D

  • @mujeebbridgetown
    @mujeebbridgetown 2 года назад

    Nice explanation

  • @abhishekshankar6305
    @abhishekshankar6305 Год назад

    you are the best

  • @jst8922
    @jst8922 9 месяцев назад

    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.

  • @studies3943
    @studies3943 Месяц назад +1

    your accent is sweet

  • @abinashpanda393
    @abinashpanda393 8 месяцев назад

    This might not pass all test cases, you have to add a delimiter like '#' while concatenating numbers in freq variable.

    • @nikoo28
      @nikoo28  8 месяцев назад

      passes all cases on Leetcode as per the problem constraints. If you have different strings patterns, it might need a little tweaking.

    • @abinashpanda393
      @abinashpanda393 8 месяцев назад

      ​@@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.

  • @fourieruddin871
    @fourieruddin871 Год назад +1

    Best

  • @sayanmanna2511
    @sayanmanna2511 9 месяцев назад +1

    But why light theme?? I am blind now..

    • @nikoo28
      @nikoo28  8 месяцев назад

      Light is easier for diagrams and animations. Will keep using light theme.

  • @devansh_4u
    @devansh_4u Год назад +1

    beats 30% java codes, wonder what could be a better solution!

    • @nikoo28
      @nikoo28  Год назад +1

      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

  • @yogeshganpule2695
    @yogeshganpule2695 2 месяца назад

    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  2 месяца назад

      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 2 месяца назад

      @@nikoo28 Thanks .

  • @himadripaul7332
    @himadripaul7332 Год назад

    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 Год назад

      @@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 года назад +1

      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. ruclips.net/video/fAJqAnEWq0o/видео.html&ab_channel=ThatIndianCoder

    • @Nishi-Tiwari
      @Nishi-Tiwari Год назад +1

      @@nikoo28 You are best!