Minimum Window Substring: Utilizing Two Pointers & Tracking Character Mappings With A Hashtable

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 24. 07. 2024
  • Code & Problem Statement @ backtobackswe.com/platform/co...
    Free 5-Day Mini-Course: backtobackswe.com
    Try Our Full Platform: backtobackswe.com/pricing
    đŸ“č Intuitive Video Explanations
    🏃 Run Code As You Learn
    đŸ’Ÿ Save Progress
    ❓New Unseen Questions
    🔎 Get All Solutions
    Question: Given a string S and a string T, find the minimum window in S which will contain all the characters in T (matching or exceeding in frequency) in complexity O(n).
    Anytime we have time reduced to linear time and we know that much must be done, that is indicative of using some sort of auxiliary structure to keep track of information for us so time can stay low in complexity.
    Complexities
    s = length of search string
    t = length of "pattern" or "character" string
    Time: O( s + t )
    At worst we will touch each element twice, once by the left pointer and once by the right pointer.
    Ex:
    s = "aaaaat"
    t = "t"
    We will spend t time to build the character requirements hashtable.
    Space: O( s + t )
    At worst the window hashtable will have a mapping for every character in s.
    At worst t will have all unique characters.
    s = "abcdef"
    t = "abcdef"
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    HackerRank: / @hackerrankofficial
    Tuschar Roy: / tusharroy2525
    GeeksForGeeks: / @geeksforgeeksvideos
    Jarvis Johnson: / vsympathyv
    Success In Tech: / @successintech
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    This question is 13.7 in the fantastic book Elements of Programming Interviews
  • Věda a technologie

Komentáƙe • 427

  • @BackToBackSWE
    @BackToBackSWE  Pƙed 5 lety +57

    Table of Contents:
    The Problem Introduction 0:00 - 1:31
    Walking Through The Brute Force 1:31 - 4:19
    Analyzing The Brute Force Solution 4:19 - 6:58
    Lower Bounding The Brute Force 6:58 - 10:25
    Let's Think Harder: Reapproaching Things 10:25 - 13:03
    First Satisfying Window Found 13:03 - 13:51
    We Now Make A Key Choice 13:51 - 17:43
    Observing The Work The More Optimal Solution Does 17:43 - 19:25
    Time Complexity 19:25 - 20:35
    Space Complexity 20:35 - 21:36
    Wrap Up 21:36 - 22:14
    The code for both Brute Force and Optimal solutions are in the link in the description. Fully commented for teaching purposes.

  • @SameerSrinivas
    @SameerSrinivas Pƙed 5 lety +88

    Thanks a lot for choosing intuition based approach. This is the most important skill in problem solving. Thanks for your time and energy spent making these videos and for writing beautiful code. Was able to understand with no confusion. Those are very intuitive variable names! Keep rocking!!!

  • @aholagunju
    @aholagunju Pƙed 5 lety +45

    Why am I just discovering this channel? This is the best explanation I have seen so far. Makes it look simple as "abc".
    Thank you Ben.

  • @Egrodo1
    @Egrodo1 Pƙed 5 lety +25

    No request, just major kudos. Your videos are by far the best leetcode explanations I've seen, please keep it up.

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 5 lety +11

      I'm trying to improve daily. Teaching is hard. It is one thing to know something. But I have to sit myself down and say...how do I communicate this?
      The effectiveness of a teaching is inversely proportional to the number of people you lose at each great intellectual "leap" (as I always say) a concept requires.

  • @jral1127
    @jral1127 Pƙed 3 lety +1

    It took me so long to finally find a resource that makes sense. Your video and website is easy to understand and pure gold. Glad I found your channel from this problem, thanks!

  • @doruwyl
    @doruwyl Pƙed 5 lety +3

    I've watched a lot of video explanations to different coding problems.
    But I can say for sure that your way of explaining things is by far the best I've seen so far.
    I consider that you really try your best to make the audience to understand the solution to the problem rather than just showing a problem.
    Well done!
    I hope you will keep up posting new videos!
    Definetively this channel should have a lot more subscribers.

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 5 lety

      yeah I will keep posting - and thanks haha, I've been at this for a while with little viewers

  • @jordanmoore7298
    @jordanmoore7298 Pƙed 4 lety +7

    Wonderful video. You made what could be a confusing concept into a clear one. I feel immensely more powerful behind the keyboard now!

  • @dankokozar
    @dankokozar Pƙed 5 lety +8

    Brilliant. I believe it's very hard to edit the video in a stop-motion fashion and you're making that effort. That makes your videos interesting from start to end. I also like big and clear letters (visible on tablet). Kudos!

  • @jlpeng9036
    @jlpeng9036 Pƙed rokem

    thank you man! your explain is wonderful!!! a lot of people tried to explain their code, but you are the first one explaining how the idea (the way we should think) to solve it without coding part. i now understand it!

  • @ponderatulify
    @ponderatulify Pƙed 3 lety

    You are a WONDERFUL educator. That's how my mind works. I can't go full abstract from the get-go. I start simple from a concrete case, specific case, then I can generalize. Always thought this was wrong, because I wasn't able to REMEMBER solutions... . Thank you man.

  • @randomguy-ew6ez
    @randomguy-ew6ez Pƙed 5 lety +5

    Thank you!! Probably the only channel in the world where I won't touch the skip ad button or use ublock origin against.

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 5 lety

      aw, thanks. Well...this channel has a long way to go...the initial videos were a rough start.

  • @edwardnewgate2198
    @edwardnewgate2198 Pƙed 5 lety +7

    Amazing work dude- I'm a fan of your code explanations! Keep em coming

  • @kannappansuresh2447
    @kannappansuresh2447 Pƙed 2 lety

    crystal clear explanation, thanks man. got stuck with problem for two days, I wanted a in-depth explanation of the algorithm and you provided it!

  • @James-yz4cc
    @James-yz4cc Pƙed 4 lety +4

    The clearest explanation on CZcams. You deserve way more subs!

  • @kaushtubrawat8223
    @kaushtubrawat8223 Pƙed 5 lety +5

    I was solving some questions by myself and had doubts in some of them such as this one..and i came across your videos ..i must say you have put a lot of hard work in explanation and also in editing of your videos..hats off..SUBSCRIBED :)

  • @kratigupta80
    @kratigupta80 Pƙed 3 lety

    You are doing a fantastic job I must say, and I just now saw your platform where u have put code, solution, video all at one place, and it is God level.

  • @xiuwenzhong7375
    @xiuwenzhong7375 Pƙed 5 lety +3

    thanks a lot for hint of this problem.
    Using one HashMap to store all the target character and the times they need to show. Once the value change to 0, match length + 1, (when fast point move), once the value change from 0 to 1, match length - 1, the way to check current substring is contain target string, we can use matchLength == map.size().

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 4 lety

      I haven't replied to this for a bit, replying to close this out in my "unresponded to comments" feed.

  • @RahulVerma-fz2jf
    @RahulVerma-fz2jf Pƙed 3 lety +1

    Really good work man. The best part is you, explaining the thinking process of how to go about optimizing brute to a better solution. Keep up the good work .

  • @namratam1522
    @namratam1522 Pƙed 4 lety +1

    Hi Ben, I had been searching for these all problems to be explained around "Why" and "How", you have made me stop my search and I struggle to believe that someone could teach better than my expectations. I am from India and love the way you teach, amazing man.

  • @xsnowcappedx
    @xsnowcappedx Pƙed 5 lety +27

    Man I just graduated and started job hunting. These videos have finally made everything I've studied start to come together ( I really couldn't understand a lot ). EVERY other video/explanation has been so confusing for me. You're genuinely giving me hope. Keep this up I really appreciate it. Do you plan to cover any kind of OOP design or system design/scalability questions?

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 5 lety +19

      Hope is the goal.
      And...yeah I want to do an OOP/system design thing but for that I need more independent study. I read "Clean Code" and "Clean Architecture" by Robert C. Martin.
      "Clean Architecture" is a fantastic, amazing, complete, book on good Object Oriented design and designing scalable OO systems.
      And comments like this inspire me but make me sad too. I have hundreds of more quality videos in me...will the world ever see them? ... This project will take at least a year to develop into the minimum of what I want it to be.
      That makes me sad.
      A lot of hard work and lonely days ahead in front of a computer screen...but it's ok.

    • @kellyxiao3060
      @kellyxiao3060 Pƙed 5 lety +4

      @@BackToBackSWE you did really really amazing work.

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 5 lety +1

      @@kellyxiao3060 haha thanks

    • @sahil_cse_guy2684
      @sahil_cse_guy2684 Pƙed 4 lety +2

      @@BackToBackSWE you will be more searched on youtube in coming months if you continue to explain like this.Never ever loose hope.GOod Luck!

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 4 lety +1

      @@sahil_cse_guy2684 thx

  • @adithyabhat4770
    @adithyabhat4770 Pƙed 4 lety +1

    I really like your approach of teaching, you start with brute force and then go on improving that.
    Thanks!

  • @fibber7062
    @fibber7062 Pƙed 4 lety +2

    Thank you for all the work you put into creating these videos! You're awesome!

  • @neerumittal9028
    @neerumittal9028 Pƙed 2 lety +1

    This is the most knowledge enhancing video i have seen for ds problems and it is to the point. keep the work good up.

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 2 lety

      Elated to hear that! Explore some awesome videos in our DSA course by subscribing on our website using "CZcams40" for a 40% discount - backtobackswe.com/pricing

  • @liingpangryantee7203
    @liingpangryantee7203 Pƙed 3 lety +2

    It makes so much sense when you understood the technique, but man no way would I be able to come up with this technique in an interview

  • @atibhiagrawal6460
    @atibhiagrawal6460 Pƙed 5 lety +3

    I have an interview of Monday and your videos are the besttttt

  • @fridagutierrezmireles1193
    @fridagutierrezmireles1193 Pƙed 4 lety +2

    I love all of your videos, thank you for making me understand everything better!

  • @HumalDiscover
    @HumalDiscover Pƙed 4 lety +1

    You suddenly make the problem so easy to understand by abstracting and explaining the main thing. Thanks

  • @aasthamehtatech
    @aasthamehtatech Pƙed 4 lety +1

    I'll mark today's date by this comment, I really did watch a few ur videos earlier, but today is when I realised the beauty of it! All this time, I jumped to problem solving directly, hoping to learn algorithm or even come up with 'em when I solve problems, now I do realise that first we need to understand the concept that deep, know y we r doing it & only then we'll able to come up with beautiful efficient soln. Also, I did like ur way of transitioning from intuitive brute force to an efficient one, that makes the content even more relatable. Thanks @BackToBackSWE :)

  • @RagazzoKZ
    @RagazzoKZ Pƙed 4 lety +11

    You are the best teacher man! Thanks!

  • @jakefromstatefarm3954
    @jakefromstatefarm3954 Pƙed 3 lety

    absolutely brilliant! thanks for taking a chance on us!

  • @TheRahul599
    @TheRahul599 Pƙed 5 lety +2

    I was just finding a teacher like you who teaches how to think, really you are a great teacher Sir......Lots of love and respect from India......

  • @tianxiaowang3771
    @tianxiaowang3771 Pƙed 5 lety +1

    The Ω part is a little confused, but another part is very clear. Thanks, Ben. your video gives me a log help

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 5 lety

      Sure. And watch this: czcams.com/video/0oDAlMwTrLo/video.html

  • @ibrahimt09
    @ibrahimt09 Pƙed 3 lety +1

    Very well explained!!! Thank you very much for taking the time and effort to walk through in this depth!

  • @xiaotongyan5394
    @xiaotongyan5394 Pƙed 4 lety +1

    great explanation. I don't know how to thank you. I really like the transition from a brute force solution to an optimal one.

  • @QVL75
    @QVL75 Pƙed rokem

    I really like the way you explained this problem. Very logical and easy to understand. Thank you!

  • @djlivestreem4039
    @djlivestreem4039 Pƙed 2 lety

    you're the best bro seriously never stop please

  • @MAK28031991
    @MAK28031991 Pƙed 5 lety +1

    One thing which will take you forward in this domain is the way to you approach problem and optimize it further. Keep it up. All the best.

  • @sophiehall38
    @sophiehall38 Pƙed 5 lety +4

    Expand the window until it satisfies, then contract the window. Nice explanation!

  • @The8merp
    @The8merp Pƙed 3 lety +2

    Thank you for the awesome explanation of both the algorithm and it's time and space complexity. I was struggling to understand the time and space complexity.

  • @youlihanshu
    @youlihanshu Pƙed 3 lety

    so well explained, such a clear quick course!

  • @abhishekbhaware6719
    @abhishekbhaware6719 Pƙed 4 lety +1

    very very thank you, sir, the way you approach is just like feeding a baby right from scratch it's just awesome this problem is right now in your assignment and I don't know how to solve it but by this, I can very easily do it

  • @MrAlus3
    @MrAlus3 Pƙed rokem

    Oh boy, oh boy. This is very good explanation. When you said this issue is consider "hard" I was suprised, since you made it so easy by breaking down this brute force and optimal solution. Cheers

  • @asittripathy1778
    @asittripathy1778 Pƙed 3 lety +1

    I am a fan of your code explanations. I must say great way to explain something in very simple way.

  • @Yunnn_life
    @Yunnn_life Pƙed 4 lety +2

    Doing leetcode for 2 days and I saw you 3 times! Subscribed!

  • @AI_For_Scientists
    @AI_For_Scientists Pƙed 2 lety +1

    teaching is an art and you are gifted with that. thank you!

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 2 lety

      Thanks! try out my 5 day free mini course for some good content backtobackswe.com/

  • @jamesdvc
    @jamesdvc Pƙed 4 lety +1

    Very well explained! Saved my time and it is very helpful! Thank you!

  • @XenaKai
    @XenaKai Pƙed 5 lety +3

    There's a LC easy question (#438) like this that my friend and I were struggling with. Brute force solution is easy to come up with, but the optimal solution requires a little bit more practice. This video explained it perfectly. I've been watching your videos daily! Ordered EPI because of you and it came in the mail this morning.

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 5 lety +2

      sweet, that's a good book. Tell me when you get into Google 😉😉

    • @XenaKai
      @XenaKai Pƙed 5 lety

      @@BackToBackSWE First phone interview in a couple weeks 🙃. I'll let you know if I make it to their on-sites!

  • @BaishaliGhosh13
    @BaishaliGhosh13 Pƙed 4 lety +1

    Thank you. The example driven explanation really brings clarity to my understanding.

  • @jishulayek8252
    @jishulayek8252 Pƙed 4 lety +2

    Excellent explanation!!! Really like to watch and learn from your tutorials.

  • @tomshannon4481
    @tomshannon4481 Pƙed 2 lety

    Your videos are so helpful and clear.

  • @sreerampanigrahi
    @sreerampanigrahi Pƙed 4 lety +1

    It was a very well made with emphasis on important words and points. Loved the video and you earned a sub.

  • @nupurjaiswal957
    @nupurjaiswal957 Pƙed 3 lety

    This is so helpful. Thanks a lot.

  • @pranavganorkar2379
    @pranavganorkar2379 Pƙed 4 lety +1

    One of the most readable codes - 100 times better than those on leetcode discuss - Very easy to understand for anyone - Actually had figured out the approach before watching your video - But had problems implementing it myself - Thanks Ben !

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 4 lety +1

      Nice, thx

    • @pranavganorkar2379
      @pranavganorkar2379 Pƙed 4 lety

      @@BackToBackSWE Just a small suggestion in your optimal code - We can maintain the frequency mapping only for required characters (those present in String t) in 'windowCharacterMapping' hashmap - As we do not care for characters which are not present in String t

  • @laxatony
    @laxatony Pƙed 5 lety +1

    Thanks for the clear explanation. You make the logic so easy to understand.

  • @satyadeeproat2012
    @satyadeeproat2012 Pƙed 4 lety +1

    I was confused while solving leetcode Sliding window questions. Leetcode discussion section didn't help. Watched this video and now I am able to solve most of sliding window medium level questions in 15-20mins. Thanks for the video

  • @rohitprasad365
    @rohitprasad365 Pƙed 3 lety

    Wow, This is the best explanation, Thank you for making our lives easier.

  • @edin1256
    @edin1256 Pƙed 2 lety

    Thank you very much, this really helped a lot.

  • @biswamohandwari6460
    @biswamohandwari6460 Pƙed 4 lety +1

    You explain like a real man... Amazing

  • @alpishjain1317
    @alpishjain1317 Pƙed 3 lety

    Awesome explanation!

  • @tushargoyal3804
    @tushargoyal3804 Pƙed 4 lety +1

    You are a brilliant teacher!!!! You really built the concepts.

  • @deepakkhobragade5257
    @deepakkhobragade5257 Pƙed 4 lety +1

    Awesome explanation! I really appreciate your efforts. Thanks!

  • @vanshmittal767
    @vanshmittal767 Pƙed 5 lety +3

    your teaching skill ismawesome man !!! love it

  • @BharCode09
    @BharCode09 Pƙed 4 lety +1

    OMG such neat intuitive explanation! Thanks for your efforts!
    Also, you have a lot of resemblance with one of my cousins and we are Indian! :)

  • @pranjalchoubey5929
    @pranjalchoubey5929 Pƙed 4 lety +1

    Beautifully explained!

  • @suhasnayak4704
    @suhasnayak4704 Pƙed 4 lety +8

    Thanks! In the code while mentioning about time complexity instead of mentioning leetcode runtime, put it in terms of big o notation, that would be more helpful.

  • @sebastianacostamolina9593
    @sebastianacostamolina9593 Pƙed 10 měsĂ­ci

    As always thank you !

  • @vekatasaiamulyapamidimukka7085

    Awesome explanation. Thank you so much for making such good videos. Helping us a lot.

  • @harishgovindan
    @harishgovindan Pƙed 4 lety +2

    Well explained!! Thanks!! I would like to know how the characters are search within the window using the hash table in O(1) time.

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 4 lety

      I don't remember this problem well nor the solution enough to answer

  • @RuthChirinos
    @RuthChirinos Pƙed 3 lety

    I've discovered the channel, great explanation, thanks!!

  • @alejandroescalante857
    @alejandroescalante857 Pƙed 4 lety +1

    EXCELLENT!!!!!! Thank you, you've made my day.

  • @saharhusseini7419
    @saharhusseini7419 Pƙed 3 lety

    Thank you for the good explanation.

  • @RDharini-yg1nm
    @RDharini-yg1nm Pƙed měsĂ­cem

    Very Helpful,
    Fantastic Explanation

  • @pkboolean
    @pkboolean Pƙed 3 lety

    dude you really are a legend

  • @Liokki
    @Liokki Pƙed 4 lety +1

    Great explanation, thanks for the video. Helped me a lot in understanding the problem in preparation for an upcoming Facebook interview

  • @rohitpal7739
    @rohitpal7739 Pƙed 4 lety +1

    best ! love how you cut videos

  • @jeffenriquez9929
    @jeffenriquez9929 Pƙed 3 lety +1

    Thank you! I was struggling with this.

  • @ramadaskamat6418
    @ramadaskamat6418 Pƙed 3 lety +3

    I wish I found this channel earlier, u r so good

  • @kirancoding1576
    @kirancoding1576 Pƙed 4 lety +5

    I can only say ,"YOU ARE THE BEST"

  • @nabidulalam6956
    @nabidulalam6956 Pƙed 3 lety

    Concise and precise explanation.

  • @Maulmota
    @Maulmota Pƙed 5 lety

    Excellent and clear explanation. In a sea of heavy accents and confusing explanations, you video is like water in the desert. Thanks!

  • @2k7Bertram
    @2k7Bertram Pƙed 2 lety

    Beautifully explained. Thanks!

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 2 lety

      Thank You, Glad you liked it.
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends :)

  • @syedimam8663
    @syedimam8663 Pƙed 4 lety +1

    Your explanations are the best in the world!

  • @gkrithika7552
    @gkrithika7552 Pƙed 3 lety

    Awesome video with great explanation. Thanks a lot for such amazing and easily understandable video

  • @MiddleEasternInAmerica
    @MiddleEasternInAmerica Pƙed 3 lety

    THANK YOU SO MUCH

  • @zhanginou
    @zhanginou Pƙed 5 lety +1

    Super clear man, thanks!

  • @watcher5232
    @watcher5232 Pƙed 3 lety

    Trust me, a very clear explanation. I will definitely donate when I pass my interview. lol

  • @sciphilo754
    @sciphilo754 Pƙed 3 lety +1

    Lovely intuitive explanation!

  • @nikhil.pandey
    @nikhil.pandey Pƙed 4 lety +1

    it's my 1st video on this channel............... and guess what? I love it by your approach to the solution .!!

  • @johnlabarge
    @johnlabarge Pƙed 5 lety +1

    Amazing explanation. You're awesome at this.

  • @Tanu-br9bp
    @Tanu-br9bp Pƙed 3 lety +1

    Just love the way you explain things. Your videos are the best. Good job 👏 👍

    • @BackToBackSWE
      @BackToBackSWE  Pƙed 3 lety

      thanks! hey

    • @Tanu-br9bp
      @Tanu-br9bp Pƙed 3 lety

      @@BackToBackSWE Hi, I am stuck on this question (www.lintcode.com/problem/word-pattern-ii/description). Can you please create a video for the same.

  • @AngadSingh97
    @AngadSingh97 Pƙed 4 lety +1

    Really nicely explained, thanks man!

  • @bibiworm
    @bibiworm Pƙed 3 lety

    21:30 I understand that it takes O(t) to build the hash table, but since there are total 26 characters, wouldn’t it take O(1) to store the hash table? Thanks.

  • @ateebahmed2237
    @ateebahmed2237 Pƙed 3 lety +1

    you earned a sub man

  • @andresserron8596
    @andresserron8596 Pƙed 3 lety

    You got it, keep on doing...

  • @darshantsdarshan1
    @darshantsdarshan1 Pƙed 4 lety +1

    Somebody give this guy a medal!

  • @shashikantdivekar7839
    @shashikantdivekar7839 Pƙed 3 lety

    Very good explanation. Thank you Sir for this quality video.

  • @cbverma2k
    @cbverma2k Pƙed 3 lety +1

    One of best explanation of complexity analysis .. keep going ... many likes

  • @ranjanrohit64
    @ranjanrohit64 Pƙed 5 lety +1

    thank you, sir, for this beautiful explanation. Made me subscribe and happy to watch your more videos and get good knowledge .

  • @enigma2886
    @enigma2886 Pƙed 3 lety +13

    I think I am dumb af, cOZ I hAve To KeEp rePlaYing ThE vIdEO
    EDIT: finally got it ! you genius teacher man !

  • @potterhead__5121
    @potterhead__5121 Pƙed 4 lety +1

    Huge thanks! You're awesome!