[Java] Leetcode 424. Longest Repeating Character Replacement [Sliding Window #6]

Поділитися
Вставка
  • Опубліковано 9 січ 2025

КОМЕНТАРІ • 21

  • @hasibqureshi6409
    @hasibqureshi6409 2 роки тому

    Thanks Eric for such a crystal clear explanation.

  • @maxmelnyk6306
    @maxmelnyk6306 2 роки тому

    Thanks for the video, Eric! It worth to mention that O(N * 26) is still linear complexity wich asymptotically approaching O(N).

  • @Dennis-en6rt
    @Dennis-en6rt 2 роки тому +1

    I like this explanation a lot! Helped a ton, thank you. Liked & Subscribed :D

  • @Kitchen-Raccoon4572
    @Kitchen-Raccoon4572 11 місяців тому

    Thank you Eric!

  • @Smile880223
    @Smile880223 9 місяців тому +2

    I think the reason we don't have to decrease the mostFreq is because mostFreq only affects our answer when it is larger than the previously largest mostFreq?

  • @nikhilm907
    @nikhilm907 3 роки тому +2

    Good explanation, you can also just keep a char pointer to most frequent char and get the count using the hashmap

    • @EricProgramming
      @EricProgramming  3 роки тому

      Nikhil M, Thank you very much for your support!

  • @SHSelect
    @SHSelect 2 роки тому

    well explained Thank you

  • @subramanyarajendramuthinti1119
    @subramanyarajendramuthinti1119 3 роки тому +1

    Nice Exaplanatoin...Thank you

  • @manojkumarmanu6907
    @manojkumarmanu6907 Рік тому

    Hi Eric Just want to know how the time complexity becomes O(N*26).could please help me with that understanding

  • @호이야-n4s
    @호이야-n4s 3 роки тому +1

    Hi, Thanks for explanation. Could you just go over why did you set the condition as the (right - left +1)? Is it because of the length?
    Thank you :)

    • @de-stressmusic432
      @de-stressmusic432 2 роки тому +1

      right - left + 1 gives us a length of our sliding window, we do +1 since index starts to count from 0.

  • @wonghuang1830
    @wonghuang1830 2 роки тому +1

    Thank you!

  • @quocnguyeninh32
    @quocnguyeninh32 2 роки тому

    I don't really understand the reason why we assure that the condition numofreplacement > k is always unmatched after peforming the shrink. For example, given a list = "aaabbc" and k =2, at the final step we have:
    {a:3,b:2,c:1}, mostfreq =3 => numofreplacement = 3 (> k=2) -> shrink => {a:2,b:2,c:1}, mostfreq = 2 -> numberofreplacement = 5 -2 =3 ( the condition is still satisfied here ). I don't really understand why you don't update the mostfreq variable after performing the shrink :

  • @ManideepSagar
    @ManideepSagar 2 роки тому +1

    What's the complexity of this algorithm?

    • @SHSelect
      @SHSelect 2 роки тому

      i would say O(n) for the time and O(26 or n) for the space

    • @tourniquet3306
      @tourniquet3306 2 роки тому

      @@SHSelect Space usage for the storage of occurrences is always 26 integer values so the space complexity will be constant i.e. O(1)

    • @ramkrishnasharma6327
      @ramkrishnasharma6327 2 роки тому +1

      @@tourniquet3306 shouldn't he use while instead of if for shrinking?

  • @SanjeevKumar-rt6ui
    @SanjeevKumar-rt6ui Рік тому +1

    Greatt