Sliding Window Technique - Algorithmic Mental Models

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • Please support me on Patreon: / thesimpleengineer
    / thesimpengineer / schachte
    ryan-schachte.com
    Don't forget to subscribe! Code:
    gist.github.com/Schachte/87d7...
    In this video, we'll begin our series of algorithmic mental models and cover the idea behind the sliding window technique. This technique allows us to reduce a typical n^2 algorithm to a linear time algorithm with minimal effort. This exploits linear time optimizations on data structures that deal with iteration and group sequential pieces of data together.
    More resources:
    / sliding-window-technique
    thesimpleengineer.com
    stackoverflow.com/questions/8...
    Timestamps
    00:00 Welcome
    8:25 Maximum sum of contiguous subarray of size 3.
    16:35 Question variants
    24:50 Dynamic variant. Smallest subarray with given sum.
    27:45 Smallest subarray code start
    32:48 Smallest subarray solution
    33:20 Longest substring with length k distinct characters

Komentáře • 391

  • @omkarpat
    @omkarpat Před 4 lety +559

    One of the best explanations of this concept. Please make some more "Algorithmic Mental Models" based videos.

    • @CEOofTheHood
      @CEOofTheHood Před 3 lety +23

      dude u seriously need to make more of these. Ill pay for them.

    • @andrewblaines
      @andrewblaines Před 3 lety +17

      Agreed! These are great. More "Algorithmic Mental Models" for dynamic programming, backtracking, etc. would be extremely helpful.
      Thanks for the video!

    • @veliea5160
      @veliea5160 Před 3 lety +9

      it is not one of the best, it is the best

    • @Mogwai88
      @Mogwai88 Před 3 lety

      @@CEOofTheHood Yes. Please make more of these. Especially with your new freecodecamp traffic this would really take off.

  • @jacktrainer4387
    @jacktrainer4387 Před 3 lety +182

    I've never before seen a CS video that approached CS like math (i.e., here are the concepts, here are some keywords to look out for so you know when to apply these concepts, here are a few examples). The world needs 1,000 more videos like this (DP, Linked Lists, Trees, Graphs, etc). Fantastic work!

  • @DonMamaril
    @DonMamaril Před 4 lety +7

    I loved, looooved the format of this! Please continue to do these videos. Extremely helpful!!

  • @neerajkulkarni6506
    @neerajkulkarni6506 Před 3 lety +7

    This is fantastic! Please make more of these 'mental model' videos. There too many videos out there that jump straight to the solution without any discussion of how to approach and generalize a problem. We need more video's like this!

  • @sujityadawad
    @sujityadawad Před 4 lety +9

    Was struggling a lot with sliding window problems earlier, your explanation really simplified those problems. I really appreciate your effort. Thank you! Please post more videos.

  • @svdfxd
    @svdfxd Před 5 lety +6

    One of the The best videos to explain Sliding windows concept. Request you to make other such videos that will help in tech interviews.

  • @maxdrojjin6984
    @maxdrojjin6984 Před 5 lety +82

    This is really the best video (or any, really) explanation of the topic I have found. Really hope this would become more popular. Thank you!

  • @dr_920
    @dr_920 Před 4 lety +9

    One of the best tutorials I have even seen. Thanks.

  • @uzvalmallepeddi8962
    @uzvalmallepeddi8962 Před 2 lety +12

    I wouldn’t resist to pay a 1000$ to watch such videos. Brilliant piece of work! Hope you do more videos on “Mental models”

  • @silvahawk
    @silvahawk Před 3 lety +5

    I have always been calculating the first windowSum in a separate loop before starting to "move" the window in a separate loop. I never knew you could do both within the same loop without using a nested loop. This is amazing!

  • @shrey4489
    @shrey4489 Před 2 lety +3

    Great explanation! I'm a visual learner and I can see myself imagining these sliding window animations when I face array problems like this in the future.

  • @alphapenguin9748
    @alphapenguin9748 Před 4 lety +3

    Please make more algorithm videos, you're literally the best explainer I have found on youtube.

  • @peacebakare
    @peacebakare Před rokem

    This is the best explanation on Sliding Window I have seen so far. Thank you for the detailed yet simple approach to explaining the concept.

  • @sedgeralt
    @sedgeralt Před rokem +2

    Hands down the best explanation of the Sliding Window technique. Please do more algorithmic mental model videos!

  • @potatocoder5090
    @potatocoder5090 Před rokem +6

    I have struggled with this concept for a really long time, but not anymore :) Your explanations were absolutely beautiful and I'm excited to solve some sliding window problems now! Can you please create more Algorithmic Mental Model videos? We'd all be super grateful!

  • @omaryahia
    @omaryahia Před 2 lety

    a simple visual explanation,
    detailed, with variants
    this is amazing, thank you

  • @VRtualboy
    @VRtualboy Před 4 lety

    I love this format, thank you for putting this together. Keep them coming!

  • @back2bits
    @back2bits Před 6 měsíci

    This is -by far- the best video on this topic I have seen. Thanks for taking the time to produce such a great content. Keep it up!

  • @Ore00000
    @Ore00000 Před 3 lety

    I greatly appreciate the clear explanation of the dynamically resizable sliding window, it cleared up some doubts I have about the algorithm. Cheers!

  • @williamahern6219
    @williamahern6219 Před 2 lety

    This is an awesome, thorough explanation of the sliding window concept and is easy to follow!

  • @rozikrazimator
    @rozikrazimator Před 2 lety +1

    Thank you, Ryan! Your explanation and visuals are simply great.

  • @weijinghuang8518
    @weijinghuang8518 Před 2 lety +1

    This is the best video I've ever seen on this topic "sliding window"! It does not only solve one or two interview questions for me but also solves a group of problems. More than that, it teaches me how to spot this group of problems. Fantastic!!!

  • @frozen_tortus
    @frozen_tortus Před 4 lety +4

    I'm absolutelly blown away how this is explained.

  • @debugquan
    @debugquan Před rokem

    Great guy. I was hesitant to watch the whole video but you were so informative that I actually learned something for many use cases. Thanks

  • @fahadhayat_
    @fahadhayat_ Před 3 lety +10

    Dude please create a playlist for the other techniques as well!!! This is gold!

    • @zappist751
      @zappist751 Před rokem

      Does he have a playlist for this?

  • @thatChillLife2037
    @thatChillLife2037 Před 2 měsíci

    dude I am only 2 minutes in and I've liked and subscribed! Between the visuals and your consice explanations, the sliding window technique (which I never thought I'd understand) makes SO MUCH SENSE! Thanks so much :)

  • @TheDev05
    @TheDev05 Před 2 lety +1

    The animation for second technique: dynamic SW is just awesome, I loved it

  • @divyanirao4279
    @divyanirao4279 Před 4 lety +38

    This video is amazing. hope you make more videos on "mental models" such as for dynamic programming.

    • @michadobrzanski2194
      @michadobrzanski2194 Před 3 lety

      Max subarray sum of k is also a dynamic programming problem. You reuse the previous max result and update it. So it is like dynamic programming with space complexity O(1).

  • @syedaffanhameed14
    @syedaffanhameed14 Před 2 lety +1

    I found "Algorithmic mental models" is a great concept for solving problems please bring more videos like this.

  • @NayanaABREU
    @NayanaABREU Před 4 lety

    Thank you so much! I finally understood "Sliding Window" technique.

  • @kirtzicdeng5736
    @kirtzicdeng5736 Před 3 lety

    Best sliding window video ever! Thank you so much! Your implementation is so elegant too. Please make more videos to cover more topics, like DP, backtracking, prefix sum, etc

  • @ShivamJha00
    @ShivamJha00 Před rokem

    After watching this one, I could solve even the hard LC problems within 15-20 mins. This is a gem of a video on this topic. Hope you make more of these on other topics, I will literally pay for it

  • @francksgenlecroyant
    @francksgenlecroyant Před 10 měsíci

    Thank you @Ryan Schachte for clarifying the sliding window technique and make it so simple just like that.
    I hope you upload a lot more vids like this bro !

  • @TheN8H
    @TheN8H Před 3 měsíci

    I've really struggled visualizing this algorithm concept and this video is extremely intuitive and detailed. Would love to have more of these videos.

  • @akhalil3482
    @akhalil3482 Před 2 lety +1

    we need more of this series! please do more!

  • @adeelzafar3299
    @adeelzafar3299 Před 4 lety +1

    Thanks for the super explanation dude. I really appreciate the amount of work you put into this video for us'all. Thanks again!

  • @SuckBoot
    @SuckBoot Před 4 lety

    Amazing instruction. Not a single word was wasted. I’m only halfway through and had to comment already! Please make more algorithm videos! :-)

  • @ibrahimhegazi3955
    @ibrahimhegazi3955 Před 19 dny

    You might be a professor or a normal student, but your explanation skills are exceptional. Add to that most of the videos explaining algorithms do not include such an amazing visualization for the data structures that we are working with. I hope one day you will have the free time to make a full algorithms and data structures for competitive programming course with such an amazing visualization. Hope you the best sir whereever you are.

  • @alonbrim
    @alonbrim Před 2 lety +1

    This video is pure gold!!! Great explanation . Everything is very clear. Thank you very much!

  • @sarthakrege269
    @sarthakrege269 Před 3 lety

    This is the best video I have ever seen on an algorithmic topic!! Please make more content like this!! Love the idea of the algorithmic mental model! :))

  • @nehajhawar411
    @nehajhawar411 Před 4 lety

    Amazing video. I have never heard of this algorithm before and now I can use it. Thanks a lot. Will stay tuned for more videos :)

  • @wittyhumour29
    @wittyhumour29 Před 3 lety

    Amazing explanation of the Sliding-Window Technique. Would love to see more of Algorithmic Mental Models.

  • @arnobchowdhury9641
    @arnobchowdhury9641 Před 3 lety

    Great explanation and thanks a lot. The way you visualized really helped to understand the concept.

  • @WhosShamouz
    @WhosShamouz Před rokem

    Rewatched some parts of it. Perfect, breathtaking. The best tutorial ever.

  • @VarunVermaUSC
    @VarunVermaUSC Před 4 lety

    Great content. I like how you focused on approach and technique towards problem solving, rather than just providing the code.

  • @shuvbhowmickbestin
    @shuvbhowmickbestin Před 2 lety +1

    what a comprehensive video! Learnt a lot, liked and subbed. Keep bringing new content, you teach really good!

  • @SheikhEddy
    @SheikhEddy Před 3 lety

    Please make more videos like this, it's one of the best things I've seen on youtube

  • @rafaeldietrich8050
    @rafaeldietrich8050 Před rokem

    This is probably hands down the best explanation of the Sliding Window technique i've seen. Great job!

  • @Shiva-zy7jq
    @Shiva-zy7jq Před 4 lety

    Best video on youtube about sliding window technique. Thank you so much.

  • @MrAlmas01kz
    @MrAlmas01kz Před 2 lety +1

    One of the best and easy explanations of this concept. thank you so much !

  • @nan5715
    @nan5715 Před 3 měsíci

    I like that you actually name your variables in a meaningful way. 👍

  • @cocoarecords
    @cocoarecords Před 3 lety +1

    wow this deserve to be a series very underrated!

  • @shriduttkothari
    @shriduttkothari Před 2 lety +4

    This is the only video which made me understand dynamic window sizing algorithm... Thank you so much 🥰

  • @jx3751
    @jx3751 Před 4 lety

    Excellent explanation. The animations really drove it home.

  • @vicente3j
    @vicente3j Před rokem +1

    Only 219k views... no way. This is by far some of the best CS-related content on CZcams, hands down. Amazing!!

  • @abhigyanchatterjee
    @abhigyanchatterjee Před 4 lety

    Superb work. This is truly the best explanation I have found in the web. I really hope you make more such videos

  • @islamegy
    @islamegy Před 4 lety

    This is really high qulity content, detailed explaination and very well presented. Hope you make more content like this. cheers

  • @sureshputta2374
    @sureshputta2374 Před 4 lety

    Great explanation and right format for learning new things, Thank you so much

  • @billycheung7095
    @billycheung7095 Před rokem

    Thanks you with tear. You constructed a solid framework for handling sliding window in my head.

  • @wintersol9921
    @wintersol9921 Před 2 lety

    Thanks a lot, great explanation. I have been looking for CZcamsrs like you all the time, good explanations with good content :D

  • @yasirayaz7832
    @yasirayaz7832 Před 2 lety

    Nice explanation. I am glad I landed here while searching for all possible solutions for solving the array problems

  • @prashanttoxeed
    @prashanttoxeed Před 4 lety

    Hands down the best explanation. Subscribed. Keep posting.

  • @brenoaps
    @brenoaps Před 3 měsíci

    A series of algorithmic mental models would be awesome, great work!

  • @TechieIndia
    @TechieIndia Před 4 lety

    the best lecture available on any platform for SWT.
    I loved this video and your way of explanation.

  • @billyfigueroa1617
    @billyfigueroa1617 Před 5 měsíci

    What an excellent, well paced, well explained video with explaining the theory but also showing it in examples
    THANK YOU!
    The more you research the more you come to understand that trying to solve all these problems individually with out knowing about techniques like these, is so painful lol

  • @maggiesayabie
    @maggiesayabie Před 4 lety +8

    Who even has the audacity to dislike such a video?? The best and simplest explanation of sliding window concept i have ever come across. Thank you sir!

    • @priyamrai5915
      @priyamrai5915 Před 5 měsíci

      will it work if array has negative elements. I think no.

  • @arunponnusamy9187
    @arunponnusamy9187 Před 4 lety

    Clear simple explanation, very easy to follow, thank you !!

  • @codesefod8527
    @codesefod8527 Před 2 lety

    1. Liked 2. Subscribed 3. Notifications Turned On. Please keep posting, one of best the best explanations for sliding window problems. Thank You Ryan!

  • @danielstatler954
    @danielstatler954 Před rokem

    first vid i see on this channel and its wonderful. good job!

  • @GoblinBlaster3000
    @GoblinBlaster3000 Před 2 lety

    Great explanation, didn't know anything about sliding window before this video and I got enough information where I could implement it no problem.

  • @harshitmittal1217
    @harshitmittal1217 Před 4 lety

    Literally the best explanation of sliding window technique.

  • @pif5023
    @pif5023 Před 5 měsíci

    Nice video! Banger as a refresher for interviews.

  • @viralmehta2542
    @viralmehta2542 Před 3 lety

    Great explanation for the problems! Code is concise!

  • @stacy623
    @stacy623 Před 3 lety

    Thanks for the great explanation! Please post more patterns to ace coding interviews!
    This one was really helpful!

  • @pjmiravalle
    @pjmiravalle Před 2 lety +3

    I came across this video after struggling with sliding window problems in preparation for my upcoming Google interview, and just wanted to thank you for the super clear explanation. I'm feeling much more confident with these problems now. 👍

    • @tomrobinson8290
      @tomrobinson8290 Před rokem +2

      Did you get into google? How was the interview!?

  • @pbard42
    @pbard42 Před 2 lety

    Wow great explanation, love the ‘teach a man to fish’ approach to the algorithm problems!

  • @priyakumar6697
    @priyakumar6697 Před 10 měsíci

    Please make more of these! This was so helpful thank you.

  • @abenakn
    @abenakn Před 4 lety

    This video finally cleared the cobwebs for me. Fantastic job explaining this!

  • @paulengland8983
    @paulengland8983 Před 4 lety +1

    More of this -- this was fantastic.

  • @ethanwu7338
    @ethanwu7338 Před 2 lety

    Dude, thank you so much for making those videos!

  • @dilipkumar2k6
    @dilipkumar2k6 Před 3 lety

    The best video on the sliding window I have seen so far. You made my day/future :-)

  • @yynnooot
    @yynnooot Před 2 lety +6

    Do you have a series for these Algorithmic Mental Models? Your video was extremely helpful and I would love to see more of these!

  • @sivanyaniv64
    @sivanyaniv64 Před 2 lety

    this is the best video I was watching about sliding window - thank you !!

  • @for461
    @for461 Před měsícem

    you are a very good teacher in layman language you are reaching. We will surely crack interviews with these

  • @abduuhany
    @abduuhany Před 2 měsíci

    I love the idea of "Algorithmic Mental Models"! Thank you so much for explaining this perfectly and I'd love to see more videos for this idea!

  • @briankimutai515
    @briankimutai515 Před 4 lety

    The best sliding window technique I’ve come across thus far

  • @rahulsbhatt
    @rahulsbhatt Před 3 lety

    What a beautiful animation, thank you so much ❤️🙏

  • @soucianceeqdamrashti8175
    @soucianceeqdamrashti8175 Před 5 lety +1

    Very well explained. Keep it up!

  • @asdakuhi8h
    @asdakuhi8h Před 3 lety

    This is such a great video. You should make more for common interview patterns!

  • @parthabhowmik4747
    @parthabhowmik4747 Před 2 lety +2

    The best lecture on sliding window technique

  • @Sedri14
    @Sedri14 Před rokem

    Best explanation so far. Thank you

  • @CantBeTamed53
    @CantBeTamed53 Před 2 lety

    Great use of graphics to explain the algorithm! :D

  • @shivsakthi37
    @shivsakthi37 Před rokem

    Wow I was amused by your teaching it all went straight into the head. Somehow CZcams algorithm suggested this gem 💎 . The fact that this video was made 4 years ago great content bro 🎉 🥳.Would be great if you make some more 'mental model' videos thank you, stay in good health ❤

  • @Ebizzill
    @Ebizzill Před 3 lety

    this was hands down the best explanation of this godforsaken concept i've been trying wrap my mind around for the longest.

  • @andrewgraham3119
    @andrewgraham3119 Před 11 měsíci

    Great explanation. It really helped me to fully understand

  • @pial2461
    @pial2461 Před 4 lety +1

    Saved my day, man! Thanks a lot

  • @bar_fun3315
    @bar_fun3315 Před 3 lety

    Just found this. Thank you so much for your hard work. Definitely going to help me in the job search.

  • @rahulkushwaha7742
    @rahulkushwaha7742 Před rokem

    I struggled for longest substring problems and now here we are i solved it by my own after watching your video thanks buddy

  • @Maybec
    @Maybec Před rokem

    Thank you for your help. Please add more videos to the algorithmic mental models series. please and thank you!

  • @danielderese3170
    @danielderese3170 Před 2 lety

    I can't thank you enough. I wish I have seen this video before I bombed in the Meta interview. Please make more videos on Algorithmic Mental Models!!!