L1. Introduction to Sliding Window and 2 Pointers | Templates | Patterns

Поділитися
Вставка
  • Опубліковано 25 бер 2024
  • Notes/Codes/Problem links under step 10 of A2Z DSA Course: takeuforward.org/strivers-a2z...
    Entire playlist: • Two Pointer and Slidin...
    Follow us on our other social media handles: linktr.ee/takeuforward

КОМЕНТАРІ • 153

  • @varun1017
    @varun1017 3 місяці тому +507

    Petition to Striver. We want strings.

  • @vect0r678
    @vect0r678 2 місяці тому +98

    Petition to Striver - We want string playlist ASAP!!

  • @rajatraj4297
    @rajatraj4297 3 місяці тому +36

    gurudev aaj ka leetcode daily dekh ke socha tha, striver ka sliding window kab aayega. aur aapne sun bhi li 😌

  • @harshsheth5545
    @harshsheth5545 Місяць тому +15

    31:28 One more big optimization is possible in the longest subarray solution.
    if (arr[r]>k) { r=r+1; l=r; sum=0}
    Here if a number itself is greater than 'k' then no subarray with that element can be a valid substring. So, we can move both left and right pointers to the next element (i.e. arr[r+1])

  • @user-of5fb6nb9e
    @user-of5fb6nb9e 3 місяці тому +27

    Despite your busy schedule, you still manage to deliver invaluable content like this. I salute you, sir! Thank you very much for the teachings.

  • @sanskargupta2739
    @sanskargupta2739 3 місяці тому +92

    Petition to striver: we want string playlist

  • @angeldeveloper
    @angeldeveloper 3 місяці тому +27

    Most awaited playlist🎉🎉🎉

  • @suryasaipalthi
    @suryasaipalthi 3 місяці тому +6

    Man, this is really cool I am ngl I came across a sliding window sum today and was struggling today to do it, and here we are. Let's strive all the way. Thank you!

  • @tanvirahammed3783
    @tanvirahammed3783 3 місяці тому +20

    Hi Striver, I'm not sure if this comment will reach you or not, but I just want to say one thing: I've been watching your videos for more than a year now and have covered a huge part of the graph and dynamic programming playlists. Whenever I watch your videos, I really fall in love with your teaching style, and of course, your smile, and sometimes your small jokes. I enjoy your videos, and it feels like you're not just my tutor; it feels like you're someone very close to me, teaching me with fun and pleasure. However, in your recent playlists, I totally miss that. It feels like you're not as friendly anymore; you're just a teacher like any other tutor. Whenever I watch videos from this playlist, sometimes I wonder what happened to you. Why are you so quiet now? Why don't you joke around anymore? After all, I love your work; it's just my opinion.

  • @tasneemayham974
    @tasneemayham974 2 місяці тому +4

    LONG AWAITEDDD SERIESS!!!
    THANK YOUUUUU STRIVERRRRRR SOO SOO OSOO MUCHHHHHH!!!!
    I am currently studying the graph series once I am done. I will jump to this one!!

  • @mansimishra7089
    @mansimishra7089 3 місяці тому +5

    This is something I was wishing 2 days back. Thanks Bhaiya :)

  • @thaman701
    @thaman701 3 місяці тому +28

    Striver bro---we want string palylist

  • @user-of8ix7oq9t
    @user-of8ix7oq9t 16 днів тому +1

    Hi, Thanks for the video first of all 😊, but at time 12:28, we can't break from the loop (as you did in else condition) as array can have negative elements further which will reduce sum and it can bring sum to less than or equal to k. That else condition is fine only when we don't have negative elements in the array.
    At 21:05, we don't need the if condition to check if sum

  • @uditpanjiyar3203
    @uditpanjiyar3203 3 місяці тому +8

    today leetcode problem of the day is based on sliding window topic , and i am searching for the playlist of sliding window on youtube and you just launched complete playlist of S.W ammazzing you are great 🙏🙏

  • @nefarious001
    @nefarious001 Місяць тому +13

    VOTE FOR STRING PLAYLIST

  • @abhay3545
    @abhay3545 2 місяці тому

    Best intro of any series on UA-cam 🎉

  • @arnav7050
    @arnav7050 3 місяці тому +6

    Thumbnail upgrade crazyyy…thanx for your efforts….eagerly waiting for strings

  • @kunalwadhai777
    @kunalwadhai777 3 місяці тому +1

    Striver Bhaiya, I have just watched the introductory video of this playlist, and feels like it's a very cool explanation, I'm getting everything that you are saying for I am very grateful to you.

  • @atulwadhwa192
    @atulwadhwa192 3 місяці тому +1

    Most awaited series

  • @franciskp9117
    @franciskp9117 3 місяці тому

    Hey man, was waiting for this playlist for a long time. Appreciate your efforts

  • @shwetanshusinha2690
    @shwetanshusinha2690 3 місяці тому +1

    Was waiting for this playlist from a long time. Thank u so much sir

  • @srishtipandey6068
    @srishtipandey6068 3 місяці тому +57

    Please upload greedy and heaps playlist too #striver

    • @KartikeyTT
      @KartikeyTT 2 місяці тому

      Greedy is coming next weekend

  • @vishwaskalra8773
    @vishwaskalra8773 3 місяці тому +2

    Today i was thinking when will striver be teaching Sliding Window nd here it comes 🎉

  • @ropurifiedwater
    @ropurifiedwater 3 місяці тому

    just saw this intro video and was able to solve the leetcode problem of the day (28th march) i am hyped up for this playlist!!

  • @user-sp8ne7hj3n
    @user-sp8ne7hj3n 3 місяці тому +2

    King is back with DSA..

  • @blitztour5924
    @blitztour5924 3 місяці тому

    Completed this amazing Video. Going to Blitz through every question/video now😈

  • @omkharade9521
    @omkharade9521 3 місяці тому +3

    My motivation to continue grinding.

  • @aishwarya156
    @aishwarya156 3 місяці тому

    Awesome Bro! Great teaching skills!

  • @ParthKamal-iy9bf
    @ParthKamal-iy9bf Місяць тому

    you are doing great work striver

  • @xavier4107
    @xavier4107 2 місяці тому +1

    Petition to Striver: We want playlists on Strings & Prefix Sum logic, heap & updated playlist on hashing

  • @user-vs8xp2kk4b
    @user-vs8xp2kk4b 3 місяці тому

    💯 / 10 teacher for dsa..

  • @ibrahimlanre4285
    @ibrahimlanre4285 3 місяці тому +1

    bro striver i am so grateful for all you do ...but please a simple request on the heaps and string playlist🙏

  • @priyanshugagiya
    @priyanshugagiya 2 місяці тому +1

    Optimization was so great 🥵 I never thought about improving 2n to n

  • @monikayadav-wb6pu
    @monikayadav-wb6pu 3 місяці тому

    Thank you so much ❤bhaiya apki sari videos kaffi helpful rahi hai hamare liye

  • @shivanshmahajan2281
    @shivanshmahajan2281 3 місяці тому

    Finnally wait is over 😊

  • @priyan8004
    @priyan8004 2 місяці тому

    Man ! you are amazing.

  • @survivourff7014
    @survivourff7014 3 місяці тому

    Tnq so much striver bhaiya...

  • @a_13_balaji_k44
    @a_13_balaji_k44 2 місяці тому +3

    5:20 why no one is talking about the issue in the first problem , the first subarray isn't considered why? and no conditions given inside while loop why?
    Here is the Correct code
    int nums[] = new int[] {6,2,3,-1,-5,1,1};
    int k = 3;
    int left = 0;
    int right = 0;
    int sum = 0;
    int maxSum = Integer.MIN_VALUE;

    while(right

    • @sultan_3006
      @sultan_3006 2 місяці тому +1

      I was also wondering why no one has commented on that part!

    • @prasannasahoo0806
      @prasannasahoo0806 Місяць тому

      we will calculate the sum for the first subarray also and we later compare it with the upcoming subarrays sum . hope I made it clear

    • @purushottam108
      @purushottam108 2 дні тому

      before going to loop we can put maxSum = sum it also work fine:
      #include
      using namespace std;
      int main(){
      int k = 2;
      vectorarr = {100,-2,1,-7,-1,10};
      int sum = 0;
      int maxsum = INT_MIN;
      for (int i = 0; i < arr.size(); i++)sum = sum + arr[i];
      int l = 0; int r = k-1;
      maxsum = sum;//so we dont miss the sum of first subarray
      while (r < arr.size()-1)
      {
      sum = sum - arr[l];
      l++;
      r++;
      sum = sum + arr[r];
      maxsum = max(maxsum,sum);
      }
      cout

  • @parthbhalerao3669
    @parthbhalerao3669 2 місяці тому +1

    Striver is god !!
    Thank you sir !!

  • @LinhHoang-ml1qo
    @LinhHoang-ml1qo Місяць тому

    thanks for your dedication !

  • @user-zk4og6sy1d
    @user-zk4og6sy1d 3 місяці тому

    Thanks for uploading 🙏

  • @JohnWickea
    @JohnWickea 3 місяці тому

    wow finally 😍 . Thanks

  • @Cool96267
    @Cool96267 Місяць тому

    Thankyou so much Striver for all you efforts throughout in delivering us so much valuable content. Any student / working professional can now be able to transition their career without paying money for courses.
    Would also like your insights on the point :
    While preparing for interviews most of the aspirants are going through the videos solely and solving the question after completely watching the video. And also are feeling lazy trying to solve the question on our own. What is the best way to complete any topic without being lazy and how should an aspirant approach any topic/playlist?

  • @user-il9wr5du1y
    @user-il9wr5du1y 2 місяці тому

    Amazing explanation, but one input from my side would be that before updating the window, we should check if(l

    • @prasannasahoo0806
      @prasannasahoo0806 Місяць тому

      i don't think so .. ig the first element is 15 then l++ will happen and r++ to so we will move to the second element and will create subarrays from there .

  • @manikantareddy9454
    @manikantareddy9454 Місяць тому

    great work sir🙌

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 18 днів тому

    NICE SUPER EXCELLENT MOTIVATED

  • @harshvardhansankpal716
    @harshvardhansankpal716 3 місяці тому +2

    5:38 in this problem the sum of first subarray is not being considered, plz store it in a separate variable and put in maxi( ) as well, or after finding the sum using for loop assign max_sum= sum; in that case we dont need an extra variable

  • @ritikanand3425
    @ritikanand3425 3 місяці тому

    Thank You for the efforts

  • @user-rk2vo5zb3e
    @user-rk2vo5zb3e 3 місяці тому

    Really Helpful!

  • @shahriaralom2903
    @shahriaralom2903 3 місяці тому

    Today i was thinking when will striver be teaching Sliding Window nd here it comes (2)

  • @unknown72900
    @unknown72900 3 місяці тому

    Thank you so much for this playlist sir 🙏🏻🫂❤️

  • @dEviL_bIsWaJiT
    @dEviL_bIsWaJiT 2 місяці тому

    Thanks a lot bhaiya 💙

  • @harshsheth5545
    @harshsheth5545 Місяць тому +3

    It is important to note that Pattern 2 is applicable for positive numbers only. In your case itself if the array was [2,5,1,7,-5,10] instead of [2,5,1,7,10] your solution would be wrong.

    • @prasannasahoo0806
      @prasannasahoo0806 Місяць тому

      can you explain how ?

    • @harshsheth5545
      @harshsheth5545 Місяць тому

      @@prasannasahoo0806 sure.
      During the execution when L is at position 0 and R is at position 3, the subarray 2,5,1,7 gives the sum 15 which is greater than 14 so L will move to position 1. The new sub array now is 5,1,7.
      Then R moves to position 4 but L does not move back to position 0. So, the subarray 2,1,5,7,-5 which is a valid array but it is not checked in this method.

  • @hat_awesome21
    @hat_awesome21 3 місяці тому +1

    Thanks a lot bro 🙏 ❤️

  • @rishabhnema2479
    @rishabhnema2479 3 місяці тому

    One playlist needed for greedy algo too.

  • @nayeemrafsan356
    @nayeemrafsan356 2 місяці тому

    this content is invaluable! can't thank you enough

  • @unemployedcse3514
    @unemployedcse3514 Місяць тому

    awesome ❤

  • @t-anime517
    @t-anime517 2 місяці тому

    guru dev dhanyawad🙏

  • @Arya20012
    @Arya20012 2 місяці тому +1

    Thank you striver ❤, you are our hero

  • @tier3wala
    @tier3wala 3 місяці тому

    Thanks for Sharing bhaiya !! Stack ka v upload kar divine !! ❤️🫠

  • @banothutharun2743
    @banothutharun2743 2 місяці тому

    superb bro

  • @kashafkhan9726
    @kashafkhan9726 3 місяці тому +1

    Was in waiting ✋️ list for this from a long time ⏲️.

  • @sushma_1704
    @sushma_1704 3 місяці тому

    Thank u very much bhaiya

  • @navinchaudhary2812
    @navinchaudhary2812 3 місяці тому

    understood bhaiya

  • @codeman3828
    @codeman3828 2 місяці тому

    Thanks. Understood

  • @torishi82
    @torishi82 Місяць тому

    Samaj aa gaya.

  • @subee128
    @subee128 3 місяці тому

    Thank you very much

  • @dipendrasingh4874
    @dipendrasingh4874 3 місяці тому

    bhaiya aaj ke contest me first time 3 question hua 🙂🙂🙂🙂because of you thank you

  • @ravigupta9784
    @ravigupta9784 2 місяці тому

    Thanks a lot🙂

  • @rajsharmawatch
    @rajsharmawatch Місяць тому

    petition to striver we want string playlist

  • @user-tk2vg5jt3l
    @user-tk2vg5jt3l 2 місяці тому

    Thank you bhaiya

  • @rishabhnema2479
    @rishabhnema2479 3 місяці тому

    Thank you Sir! There was no playlist or videos regarding two pointers or sliding window on UA-cam. Leetcode daily is asking problems related to it currently, would prove to be of great help.

    • @ankittjindal
      @ankittjindal 3 місяці тому

      Check aditya verma sliding window playlist too bro

  • @NikhilKumar-xg7re
    @NikhilKumar-xg7re 3 місяці тому

    Much needed playlist
    btw which app do you use for notes ?? what is the name of this app ??♥♥♥

  • @impatientgaming9868
    @impatientgaming9868 2 місяці тому

    Great

  • @Chai_parathe
    @Chai_parathe 3 місяці тому +2

    Striver pls make string playlist 🥺

  • @parth2439
    @parth2439 3 місяці тому

    LETS GOO...

  • @prajyot2021
    @prajyot2021 5 днів тому

    thanks Raj

  • @thestarters9799
    @thestarters9799 3 місяці тому +1

    For else if(sum > k) break;
    There may be negative elements in array right?

  • @user-ym1nv1pw8i
    @user-ym1nv1pw8i 5 днів тому

    Revise optimal @30:00
    Understood!
    Mark for revision

  • @Shivam-fl6uv
    @Shivam-fl6uv 3 місяці тому

    Thank You

  • @whatsyoursin
    @whatsyoursin 2 місяці тому +2

    Those who agree we need strings playlist.

  • @saketjaiswal9381
    @saketjaiswal9381 2 місяці тому

    Done Sir😎

  • @aniketrangari8679
    @aniketrangari8679 Місяць тому

    simplest way to learn

  • @RitikRaj-we2sc
    @RitikRaj-we2sc 3 місяці тому

    Hey striver great video as usual.
    I wanted to ask about the update on intern position that you posted on linkedin. Have you started to review the assignments ?

  • @JohnJoe-pd9ph
    @JohnJoe-pd9ph 26 днів тому

    Nice

  • @akashsoam7581
    @akashsoam7581 3 місяці тому +1

    we a similar small playlist for prefix sum

  • @SanjeevM-yc5uj
    @SanjeevM-yc5uj 2 місяці тому

    For the 3rd type where you find the number of subarrays satisfying the condition, can’t we just add an extra variable and check if the subarray is satisfying the equal condition and then increase the variable’s value accordingly. Like for example can’t we just include a variable called sub_array_count and then add 1 to it whenever sum = k inside the loop itself?

  • @kanishkbairagi409
    @kanishkbairagi409 2 місяці тому

    Request to striver. We want strings playlists

  • @ok-jg9jb
    @ok-jg9jb 3 місяці тому

    Thanks❤

  • @sparshyadav9709
    @sparshyadav9709 3 місяці тому

    Understood.

  • @A_Myth963
    @A_Myth963 3 місяці тому

    God is here... Ab koi bhi qn aa jaye sliding window ka contest mei🤝

  • @abhinavnarula7300
    @abhinavnarula7300 3 місяці тому +2

    I have a small doubt in the 2nd pattern's better approach, shouldn't we also check for l

    • @AjithKumaR-jw9wt
      @AjithKumaR-jw9wt 2 місяці тому

      Yes, at the end we can put a condition if r less than l mean r equal to l plus one

  • @anujkapri6054
    @anujkapri6054 3 місяці тому +4

    Can we have playlist on strings. Please

  • @kaustubhthakur5178
    @kaustubhthakur5178 3 місяці тому

    string algorithms ,suffix arrays

  • @labadepradip7734
    @labadepradip7734 3 місяці тому

    completed

  • @rishabhnema2479
    @rishabhnema2479 3 місяці тому +1

    Could you please add additional problems where instead of sum, product of subarrays pattern is taken.

  • @Dsa_withjay
    @Dsa_withjay 3 місяці тому

    ❤️

  • @ayush.kumar_02
    @ayush.kumar_02 3 місяці тому

    First 👍

  • @parvahuja7618
    @parvahuja7618 3 місяці тому

    consistency 100

  • @anmolkumar-pi5jv
    @anmolkumar-pi5jv 3 місяці тому

    🎉🎉🎉🎉🎉🎉🎉🎉🎉