Sliding Window Technique - Algorithmic Mental Models

2024 ж. 13 Мам.
315 849 Рет қаралды

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

Пікірлер
  • One of the best explanations of this concept. Please make some more "Algorithmic Mental Models" based videos.

    @omkarpat@omkarpat4 жыл бұрын
    • dude u seriously need to make more of these. Ill pay for them.

      @CEOofTheHood@CEOofTheHood3 жыл бұрын
    • Agreed! These are great. More "Algorithmic Mental Models" for dynamic programming, backtracking, etc. would be extremely helpful. Thanks for the video!

      @andrewblaines@andrewblaines3 жыл бұрын
    • it is not one of the best, it is the best

      @veliea5160@veliea51603 жыл бұрын
    • @@CEOofTheHood Yes. Please make more of these. Especially with your new freecodecamp traffic this would really take off.

      @Mogwai88@Mogwai882 жыл бұрын
  • 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!

    @jacktrainer4387@jacktrainer43873 жыл бұрын
  • I loved, looooved the format of this! Please continue to do these videos. Extremely helpful!!

    @DonMamaril@DonMamaril4 жыл бұрын
  • Thank you so much! I finally understood "Sliding Window" technique.

    @NayanaABREU@NayanaABREU3 жыл бұрын
  • 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.

    @sujityadawad@sujityadawad4 жыл бұрын
  • 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!

    @neerajkulkarni6506@neerajkulkarni65063 жыл бұрын
  • I love this format, thank you for putting this together. Keep them coming!

    @VRtualboy@VRtualboy4 жыл бұрын
  • One of the The best videos to explain Sliding windows concept. Request you to make other such videos that will help in tech interviews.

    @svdfxd@svdfxd4 жыл бұрын
  • 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!

    @potatocoder5090@potatocoder5090 Жыл бұрын
  • 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!

    @silvahawk@silvahawk3 жыл бұрын
  • Thank you, Ryan! Your explanation and visuals are simply great.

    @rozikrazimator@rozikrazimator2 жыл бұрын
  • One of the best tutorials I have even seen. Thanks.

    @dr_920@dr_9204 жыл бұрын
  • I'm absolutelly blown away how this is explained.

    @frozen_tortus@frozen_tortus4 жыл бұрын
  • I wouldn’t resist to pay a 1000$ to watch such videos. Brilliant piece of work! Hope you do more videos on “Mental models”

    @uzvalmallepeddi8962@uzvalmallepeddi89622 жыл бұрын
  • Please make more algorithm videos, you're literally the best explainer I have found on youtube.

    @alphapenguin9748@alphapenguin97483 жыл бұрын
  • This is an awesome, thorough explanation of the sliding window concept and is easy to follow!

    @williamahern6219@williamahern62192 жыл бұрын
  • we need more of this series! please do more!

    @akhalil3482@akhalil34822 жыл бұрын
  • 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.

    @shrey4489@shrey44892 жыл бұрын
  • 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!

    @maxdrojjin6984@maxdrojjin69844 жыл бұрын
  • More of this -- this was fantastic.

    @paulengland8983@paulengland89834 жыл бұрын
  • Thanks for the super explanation dude. I really appreciate the amount of work you put into this video for us'all. Thanks again!

    @adeelzafar3299@adeelzafar32994 жыл бұрын
  • Great explanation and right format for learning new things, Thank you so much

    @sureshputta2374@sureshputta23744 жыл бұрын
  • 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 :)

    @nehajhawar411@nehajhawar4114 жыл бұрын
  • Excellent explanation. The animations really drove it home.

    @jx3751@jx37514 жыл бұрын
  • wow, this is amazing. thank you so much

    @maidul13@maidul134 жыл бұрын
  • what a comprehensive video! Learnt a lot, liked and subbed. Keep bringing new content, you teach really good!

    @shuvbhowmickbestin@shuvbhowmickbestin2 жыл бұрын
  • I greatly appreciate the clear explanation of the dynamically resizable sliding window, it cleared up some doubts I have about the algorithm. Cheers!

    @Ore00000@Ore000003 жыл бұрын
  • Clear simple explanation, very easy to follow, thank you !!

    @arunponnusamy9187@arunponnusamy91873 жыл бұрын
  • Amazing explanation of the Sliding-Window Technique. Would love to see more of Algorithmic Mental Models.

    @wittyhumour29@wittyhumour293 жыл бұрын
  • Great explanation and thanks a lot. The way you visualized really helped to understand the concept.

    @arnobchowdhury9641@arnobchowdhury96413 жыл бұрын
  • 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

    @debugquan@debugquan Жыл бұрын
  • This video is amazing. hope you make more videos on "mental models" such as for dynamic programming.

    @divyanirao4279@divyanirao42794 жыл бұрын
    • 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).

      @michadobrzanski2194@michadobrzanski21942 жыл бұрын
  • 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

    @kirtzicdeng5736@kirtzicdeng57363 жыл бұрын
  • Very well explained. Keep it up!

    @soucianceeqdamrashti8175@soucianceeqdamrashti81754 жыл бұрын
  • Thanks for the great explanation! Please post more patterns to ace coding interviews! This one was really helpful!

    @stacy623@stacy6232 жыл бұрын
  • This video finally cleared the cobwebs for me. Fantastic job explaining this!

    @abenakn@abenakn4 жыл бұрын
  • I like that you actually name your variables in a meaningful way. 👍

    @nan5715@nan571520 күн бұрын
  • Hands down the best explanation of the Sliding Window technique. Please do more algorithmic mental model videos!

    @sedgeralt@sedgeralt Жыл бұрын
  • This is really high qulity content, detailed explaination and very well presented. Hope you make more content like this. cheers

    @islamegy@islamegy4 жыл бұрын
  • Great content. I like how you focused on approach and technique towards problem solving, rather than just providing the code.

    @VarunVermaUSC@VarunVermaUSC4 жыл бұрын
  • a simple visual explanation, detailed, with variants this is amazing, thank you

    @omaryahia@omaryahia2 жыл бұрын
  • Please make more videos like this, it's one of the best things I've seen on youtube

    @SheikhEddy@SheikhEddy3 жыл бұрын
  • The animation for second technique: dynamic SW is just awesome, I loved it

    @TheDev05@TheDev052 жыл бұрын
  • This video is pure gold!!! Great explanation . Everything is very clear. Thank you very much!

    @alonbrim@alonbrim2 жыл бұрын
  • wow this deserve to be a series very underrated!

    @cocoarecords@cocoarecords3 жыл бұрын
  • 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.

    @peacebakare@peacebakare Жыл бұрын
  • Dude please create a playlist for the other techniques as well!!! This is gold!

    @fahadhayat_@fahadhayat_2 жыл бұрын
    • Does he have a playlist for this?

      @zappist751@zappist751 Жыл бұрын
  • Hands down the best explanation. Subscribed. Keep posting.

    @prashanttoxeed@prashanttoxeed4 жыл бұрын
  • Rewatched some parts of it. Perfect, breathtaking. The best tutorial ever.

    @WhosShamouz@WhosShamouz Жыл бұрын
  • Amazing instruction. Not a single word was wasted. I’m only halfway through and had to comment already! Please make more algorithm videos! :-)

    @SuckBoot@SuckBoot4 жыл бұрын
  • What a beautiful animation, thank you so much ❤️🙏

    @rahulsbhatt@rahulsbhatt3 жыл бұрын
  • 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! :))

    @sarthakrege269@sarthakrege2693 жыл бұрын
  • Superb work. This is truly the best explanation I have found in the web. I really hope you make more such videos

    @abhigyanchatterjee@abhigyanchatterjee4 жыл бұрын
  • Do you have a series for these Algorithmic Mental Models? Your video was extremely helpful and I would love to see more of these!

    @yynnooot@yynnooot2 жыл бұрын
  • One of the best and easy explanations of this concept. thank you so much !

    @MrAlmas01kz@MrAlmas01kz2 жыл бұрын
  • This is the best explaination that i have came across 🙂

    @SantoshPrajapati-ps9nj@SantoshPrajapati-ps9njАй бұрын
  • Only 219k views... no way. This is by far some of the best CS-related content on KZhead, hands down. Amazing!!

    @vicente3j@vicente3j Жыл бұрын
  • Saved my day, man! Thanks a lot

    @pial2461@pial24614 жыл бұрын
  • 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!

    @back2bits@back2bits4 ай бұрын
  • I found "Algorithmic mental models" is a great concept for solving problems please bring more videos like this.

    @syedaffanhameed14@syedaffanhameed142 жыл бұрын
  • Best video on youtube about sliding window technique. Thank you so much.

    @Shiva-zy7jq@Shiva-zy7jq4 жыл бұрын
  • I've really struggled visualizing this algorithm concept and this video is extremely intuitive and detailed. Would love to have more of these videos.

    @TheN8H@TheN8H29 күн бұрын
  • Great explanation, didn't know anything about sliding window before this video and I got enough information where I could implement it no problem.

    @GoblinBlaster3000@GoblinBlaster3000 Жыл бұрын
  • Nice video! Banger as a refresher for interviews.

    @pif5023@pif50233 ай бұрын
  • A series of algorithmic mental models would be awesome, great work!

    @brenoaps@brenoaps24 күн бұрын
  • really good explanation and walk through. awesome presentation.

    @TheRajmoney@TheRajmoney4 жыл бұрын
  • Just found this. Thank you so much for your hard work. Definitely going to help me in the job search.

    @bar_fun3315@bar_fun33153 жыл бұрын
  • Great explanation for the problems! Code is concise!

    @viralmehta2542@viralmehta25423 жыл бұрын
  • Thank you for GREAT explanation!

    @victorklimov3175@victorklimov3175 Жыл бұрын
  • Thanks you with tear. You constructed a solid framework for handling sliding window in my head.

    @billycheung7095@billycheung7095 Жыл бұрын
  • 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!!!

    @weijinghuang8518@weijinghuang85182 жыл бұрын
  • This is such a great video. You should make more for common interview patterns!

    @asdakuhi8h@asdakuhi8h3 жыл бұрын
  • Much appreciated. Great watch

    @rogerprz@rogerprz Жыл бұрын
  • The best sliding window technique I’ve come across thus far

    @briankimutai515@briankimutai5154 жыл бұрын
  • That was really good. Thank you so much !

    @rawanfouda2291@rawanfouda22914 жыл бұрын
  • The best lecture on sliding window technique

    @parthabhowmik4747@parthabhowmik47472 жыл бұрын
  • very declariative and well explained , thanks

    @user-mq8dn1pv3v@user-mq8dn1pv3v5 ай бұрын
  • 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!

    @maggiesayabie@maggiesayabie3 жыл бұрын
    • will it work if array has negative elements. I think no.

      @priyamrai5915@priyamrai59153 ай бұрын
  • Best explanation so far

    @tusharborole6155@tusharborole61554 жыл бұрын
  • Thanks a lot, great explanation. I have been looking for KZheadrs like you all the time, good explanations with good content :D

    @wintersol9921@wintersol99212 жыл бұрын
  • This is a wonderful video, thank you so much for the great explanation.

    @alejandrabricio5697@alejandrabricio56973 жыл бұрын
  • Amazing explanation! Thank you.

    @maorcohen8628@maorcohen86283 жыл бұрын
  • This is the only video which made me understand dynamic window sizing algorithm... Thank you so much 🥰

    @shriduttkothari@shriduttkothari2 жыл бұрын
  • Literally the best explanation of sliding window technique.

    @harshitmittal1217@harshitmittal12174 жыл бұрын
  • Nice explanation. I am glad I landed here while searching for all possible solutions for solving the array problems

    @yasirayaz7832@yasirayaz78322 жыл бұрын
  • Amazing explanation, you are a great teacher!

    @feridiskenderov3974@feridiskenderov3974 Жыл бұрын
  • 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

    @ShivamJha00@ShivamJha0010 ай бұрын
  • Dude, thank you so much for making those videos!

    @ethanwu7338@ethanwu73382 жыл бұрын
  • great explanation! can't understand it better. Thank you for the video!!

    @shresthajha3454@shresthajha34542 жыл бұрын
  • Nicely done.

    @cliffordino@cliffordino4 жыл бұрын
  • Thanks for such nice explanation!

    @amangautam2792@amangautam27924 жыл бұрын
  • Explaind the Topic in an easy manner .Enjoyed the vedio and Found Really Helpful.

    @tarungopal3065@tarungopal30654 жыл бұрын
  • this is the best video I was watching about sliding window - thank you !!

    @sivanyaniv64@sivanyaniv642 жыл бұрын
  • Wow great explanation, love the ‘teach a man to fish’ approach to the algorithm problems!

    @pbard42@pbard422 жыл бұрын
  • first vid i see on this channel and its wonderful. good job!

    @danielstatler954@danielstatler954 Жыл бұрын
  • The best video on the sliding window I have seen so far. You made my day/future :-)

    @dilipkumar2k6@dilipkumar2k63 жыл бұрын
  • Great explanation. Do more videos like this!

    @pmarets@pmarets4 жыл бұрын
  • the best lecture available on any platform for SWT. I loved this video and your way of explanation.

    @TechieIndia@TechieIndia3 жыл бұрын
  • Excellent explanation, thanks!

    @felipemelendez5741@felipemelendez57412 жыл бұрын
  • This is awesome! Thank you!

    @jocelynhing6593@jocelynhing65934 жыл бұрын
KZhead