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

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ธ.ค. 2024

ความคิดเห็น • 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!

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

  • @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

  • @vishwajithshivanandaihmata2217
    @vishwajithshivanandaihmata2217 2 ปีที่แล้ว +2

    great Job!! Thank you.

  • @divyanshtripathi4867
    @divyanshtripathi4867 ปีที่แล้ว

    Amazing trick!

  • @EmmanuelAgyapong-jn6ue
    @EmmanuelAgyapong-jn6ue 9 หลายเดือนก่อน

    Thank you so much, bro!

  • @wonghuang1830
    @wonghuang1830 2 ปีที่แล้ว +2

    Thank You!

  • @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 10 หลายเดือนก่อน

      It's happened to me a lot of times