[Java] Leetcode 76. Minimum Window Substring [Sliding Window #8]

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

КОМЕНТАРІ • 20

  • @MangoTroll34
    @MangoTroll34 Рік тому +2

    Thank you for the explanation! I was able to solve this problem using a condition 'window contains the min number of t characters' however I was using a set and two frequency maps so the solution was slow. It is nice to learn about a better & faster way to solve these problems with just one frequency map :)

  • @zongchenli9738
    @zongchenli9738 2 роки тому +4

    thank you for your explanation!

  • @vishwajithshivanandaihmata2217
    @vishwajithshivanandaihmata2217 2 роки тому +2

    great Job!! Thank you.

  • @EmmanuelAgyapong-jn6ue
    @EmmanuelAgyapong-jn6ue 10 місяців тому

    Thank you so much, bro!

  • @mehboobshah4807
    @mehboobshah4807 2 роки тому +2

    Please do mention Time and Space complexity of the code in the description

    • @alexshay7969
      @alexshay7969 Рік тому +1

      I believe the time is O(n) and time complexity is O(n) as well

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

    Amazing trick!

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

    Thank You!

  • @alexshay7969
    @alexshay7969 Рік тому +1

    One thing I don't get is why minLen is set to Max_Value. For line 33 isn't it usually always going to be true? I don't understand setting curWindow to minLen also. Could you explain? Thank you!!

    • @alexshay7969
      @alexshay7969 Рік тому +1

      ok, I stepped into the code and I think you set an artificial large number to avoid chances of overlap. What's important is the while condition that matches the condition and assigning of minLen to a min window length to get the operation started. Thank you!!

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

      The way I think about it is, say you're looking for the cheapest car in a list of cars. So you set a minCar value to like 1,000,000 and then as you check cars, if you find one less than that, you update the minCar value to that value (say 400,000). If you find something less than THAT, update again, and then at the end whatever minCar is, that's the cheapest one.
      But what if every car on the list is actually greater than 1,000,000? Then minCar never updates, and you "think" the cheapest car is 1,000,000 since the value was never updated.
      That's why you set the minCar value as high as possible from the beginning. This way the first time you test a car, it will ALWAYS be the cheapest, so the minCar actually updates.

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

    Wouldn't ++arr[leftChar] > 0 hold true for every character?

    • @marcosribeiro2304
      @marcosribeiro2304 11 місяців тому +1

      at the point u get to the shrink logic your R pointer is ahead already, so map[arr[right]]--; will make sure the character will be -1 before ++arr[leftChar]

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

    Store freq if t in 1 map and change it acc to main string and finally give output

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

    It's very weird that your code runs at 7ms and mine is around 125ms. Both are exactly the same code. Magic?

    • @HeroHunter07
      @HeroHunter07 11 місяців тому

      It's happened to me a lot of times