Solve Subarray Problems Quickly With Sliding Window Technique | FREE DSA Course in JAVA | Lecture 79

Поделиться
HTML-код
  • Опубликовано: 20 авг 2024

Комментарии • 149

  • @RishiRajMusa
    @RishiRajMusa Месяц назад

    such a great way of teaching

  • @ranadheernakka56
    @ranadheernakka56 2 месяца назад

    wow bro i love your style of teaching thank you i understood where will

  • @SasiPratheek-lb3bz
    @SasiPratheek-lb3bz Месяц назад

    Superb sir 🎉 just no words 🎉

  • @khaledalaa9732
    @khaledalaa9732 6 месяцев назад

    thank you

  • @madeinscript4623
    @madeinscript4623 Месяц назад

    Thank u sir 🎉❤❤❤❤

  • @jayakumarsivasankar9683
    @jayakumarsivasankar9683 3 месяца назад

    Amazing❤

  • @hottopics4530
    @hottopics4530 27 дней назад

    this my friend is cool.

  • @susmithaa8360
    @susmithaa8360 4 месяца назад

    super sir

  • @chandruram7553
    @chandruram7553 6 месяцев назад

    Tnx bro :)

  • @shahidavalisyed487
    @shahidavalisyed487 2 месяца назад

    👍

  • @user-vx3fx1gb2c
    @user-vx3fx1gb2c 2 месяца назад

    we should also check for first wsum may be first one is maximum before sliding

  • @user-mw4hg8pf9m
    @user-mw4hg8pf9m 4 месяца назад +17

    20:50 algorithm typos mistake =>wsum=wsum-a[i-k]+a[i] instead of "- "you write "+" and one more is in coding that is for first 3 array we can intalize it in "msum" i think u understand
    but thanks for your awesome explanation really like it

  • @_MOHAMMADASHRAF
    @_MOHAMMADASHRAF 4 месяца назад +1

    thank you so much for clearing the concept of sliding window . sir but i think the comparison of the sum of the first window is missing in the code. If i am not wrong to fix that logical error we must assign the sum of first window to maximum sum
    ( Sum = wSum ) just after first for loop.

  • @sayanroy3159
    @sayanroy3159 Год назад +48

    After Kunal kushwaha this channel is best for learning DSA

    • @Neuroage24
      @Neuroage24 4 месяца назад +10

      Kunal kushwaah teaching well but sometimes he make more hype

  • @SiddharthAtrey
    @SiddharthAtrey 5 месяцев назад +1

    Any similar LeetCode Question with this topic??

  • @11csepratikshaargulewar71
    @11csepratikshaargulewar71 Год назад +30

    Sir ,it must be wsum =(wsum-a[i-k] )+a[ i ]

    • @sumanjyoti6063
      @sumanjyoti6063 3 месяца назад

      no, it must be wSum= (cSum-a[i-k]+a[i]) at the timeframe you mentioned, at the end while coding, correct formula has been applied by Sir

  • @saketnigam1733
    @saketnigam1733 Месяц назад +1

    brilliant ... from editing to teaching

  • @imranzafar3653
    @imranzafar3653 Месяц назад

    I have a very simple technique to do this first create your window and then make it slide. Window creating is simple just keep on adding the array elements till i = k - 1 and then slide with this logic
    For ( i to len-1)
    Wsum += arr[i]
    If (i > = k-1)
    Maxsum = max(maxsum,wsum)
    Wsum= wsum - arr[ n- (k-1)]

  • @taranimalayala1895
    @taranimalayala1895 7 месяцев назад

    sir u r explanation is good but there is small mistake in naive approach
    int sum=0, maxsum = Integer.min_value;
    for(int i=0; i

  • @shovarnudutta2559
    @shovarnudutta2559 11 месяцев назад +26

    Nobody explained this particular topic better than you. More power to you.

  • @Riyakumari-cm8ks
    @Riyakumari-cm8ks 5 месяцев назад

    Sir, for the first window that is from 0 to K after calculating sum we should compare it with mSum as it may be the maximum then we proceed with the next window.

  • @chintu4609
    @chintu4609 Год назад +9

    sir you are gift for us. thank you so much for these videos

  • @abdulazeem1936
    @abdulazeem1936 3 месяца назад

    Thanks for the effort and clear explanation. I found the code solution might not work if int arr[]={1000,9,31,-4,21,7}; in this case the result should be 1040. Please add the mSum=Math.max(wSum,mSum); after the first for loop.
    public class SlidingWindow {
    public static void main(String args[]){
    int arr[]={1000,9,31,-4,21,7};
    int k=3;
    System.out.println(findMaxSubArray(arr,k));
    }
    public static int findMaxSubArray(int[] arr, int k){
    int wSum=0;
    int mSum=Integer.MIN_VALUE;
    for(int i=0;i

  • @harargeetube9807
    @harargeetube9807 9 месяцев назад

    you are a man of logic and father of Teaching for me bro i like your Teaching
    what about this sir?
    int max= Integer.MIN_VALUE;
    for (int i=0;imax){
    max= arr[i]+arr[i+1]+ arr[i+2];
    }
    }
    return max;
    }
    // O(n) ??

  • @DileepV-on7wk
    @DileepV-on7wk 3 месяца назад +1

    Really Given knowledge with unique style

  • @AshokSekar-kd3ns
    @AshokSekar-kd3ns 3 месяца назад +5

    Explanation is good, But there is a minor issue with the code, if you rearrange the array elements this code won't work, you need to do the comparison right after the firstLoop as well
    for (int i=0; i

  • @starvingsouls21
    @starvingsouls21 5 месяцев назад

    if the first sliding window yields the maximum sum then it would return that as a result. Comparison has to also made for the sum of first sliding window.

  • @topricano9964
    @topricano9964 Месяц назад

    u look Anirudh Ravichander(Famous Tamil Music director) ;)

  • @francksgenlecroyant
    @francksgenlecroyant 11 месяцев назад +6

    This guy is just incredibly talented at explaining stuffs in a much more simpler way. Thanks a lot!

  • @nityaranjan6714
    @nityaranjan6714 4 месяца назад

    Sliding window also here we are using two for loops. Is not the time complexity O(n2) here?

  • @gayatrimamidwar8364
    @gayatrimamidwar8364 4 месяца назад

    One of the best explanation on sliding window. Today I understood the concept clearly. Thanks a lot sir

  • @prabhanjanmanagooli5666
    @prabhanjanmanagooli5666 2 месяца назад

    Very crystal clear explanation 👌 👏

  • @harshatejapotumarthi7555
    @harshatejapotumarthi7555 5 месяцев назад +2

    In naive approach make csum = 0 for every iteration if i. and in inner for loop j must go from i to i+k-1.. also wsum = wsum -a[i-k]+a[i] i runs from i=k to i

  • @anirudhbhat1442
    @anirudhbhat1442 8 месяцев назад +1

    The CLEANEST explanation of this concept ..... Best video for sliding windows till now

  • @mdfardeenkhan3653
    @mdfardeenkhan3653 10 месяцев назад

    After the first loop there should be a -> msum=wsum;

  • @SurajSharma-fw5fg
    @SurajSharma-fw5fg 4 месяца назад

    Very awesome !!!!!! cleared all point to point.

  • @tgmani4525
    @tgmani4525 10 месяцев назад

    at 8:50
    the j loop should be looped from i to i+k
    not i to k

  • @cleverengineer2410
    @cleverengineer2410 4 месяца назад

    finally I understand this concept some one as explained it so well I am subscribing

  • @lalanabiridi8358
    @lalanabiridi8358 10 месяцев назад +1

    anirudh ravichander if he didnt choose music

  • @realravijha
    @realravijha 2 месяца назад

    Excellent!!
    Thank you❤

  • @BiswajitDas-lk7pp
    @BiswajitDas-lk7pp 6 месяцев назад

    KL RAHUL

  • @jasper5016
    @jasper5016 10 месяцев назад +3

    You are the best teacher that I found to explain leetcode. There are so many videos but no one could explain it so nicely. Animation and Java code makes it so simple to understand. Thanks so much brother!

  • @RishiRajMusa
    @RishiRajMusa Месяц назад

    at 15:40
    when you said remove 9
    you actually removed 15
    and when you said add 21
    you actually added 26
    the answer was right 48 but the process was wrong

  • @saurabhyadav1996
    @saurabhyadav1996 7 месяцев назад +1

    Video is very informative and the way you explain is wonderful.
    There is one mistake in program ,if max sum of array is in first window so in that case logic will failed because you couldn't compare first window sum with next window sum.
    add below line at line no.-10
    mSum=wSum;

  • @tushartalekar7
    @tushartalekar7 11 месяцев назад +2

    What a lecture .... sir It's too nice. You cleared the concept very nicely.

  • @mr.viet-gaming3612
    @mr.viet-gaming3612 Месяц назад

    At 19:41 shouldn't it be wsum=csum-a[i-k]+a[I];

  • @syamprasadupputalla8233
    @syamprasadupputalla8233 11 месяцев назад +6

    I'm really wondering how such good content can be available for free.. Really appreciate your efforts and content❤❤.thank you team.

  • @angelcbency4459
    @angelcbency4459 8 месяцев назад

    Good explanation and teaching style. Thank you so much.

  • @_satveer
    @_satveer 5 месяцев назад

    never thought this would be that easier. Just wow explanation 🤩

  • @abzzz-y7o
    @abzzz-y7o 9 месяцев назад

    a very clear explanation. thank you

  • @sapnokasahar3098
    @sapnokasahar3098 Год назад

    Really sir , it was simply understanding approach to teach .
    Thank you!!!!

  • @gabrielasalvo7080
    @gabrielasalvo7080 5 месяцев назад

    amazing and right to the point explanation! Thanks!

  • @prakashnavin6245
    @prakashnavin6245 11 месяцев назад +1

    Amazing sir for so long I was very confused about this topic but today I am very clear with this topic. Thank you sir thank you very much

  • @prajaktachachad477
    @prajaktachachad477 8 месяцев назад

    You explained it so well. Simply Amazing !!!!Keep making such videos, it was truly helpful

  • @GHCSAnushaND
    @GHCSAnushaND 9 месяцев назад

    Sir your explanations is the best🎉 you made the topic very easy

  • @adityachaudhari8386
    @adityachaudhari8386 5 месяцев назад

    Thank you

  • @asdsf81
    @asdsf81 Год назад

    for(int i = 0 ; i

  • @azadchauhan963
    @azadchauhan963 5 месяцев назад

    Nice explanation !

  • @mayankkumar6628
    @mayankkumar6628 4 месяца назад

    This is a simple problem the main problem comes when interviewer ask that each sub array should contain distinct elements

  • @jaikumarm6964
    @jaikumarm6964 9 месяцев назад

    wonderful explanation ,crystal clear Thanks a lot

  • @seattlehan9684
    @seattlehan9684 Год назад

    Best explanation bout sliding windows ever. Thank you for the video!

  • @KRajesh-ej7dy
    @KRajesh-ej7dy Год назад +1

    This Video Was Amazing...Sir the concept of Sliding window was too good....

    • @TAPACADEMY
      @TAPACADEMY  Год назад +3

      Do share the course in your college community. Let's help each student in understanding DSA.

  • @user-hy5sg4fo5v
    @user-hy5sg4fo5v Год назад

    really easy method thank you so much sir

  • @shreyaskulkarni4805
    @shreyaskulkarni4805 7 месяцев назад

    Best detailed explanation of the algorithm. Great video. 👍 Keep it up.

  • @techeduka2806
    @techeduka2806 9 месяцев назад

    thanks for clear concept

  • @cod_with_sidhh123
    @cod_with_sidhh123 6 месяцев назад

    Your teaching skills is absolutely gorgeous sirrrrr

  • @meghanaraikar2705
    @meghanaraikar2705 9 месяцев назад

    Explaination was very good. Literally loved the way you explained.

  • @AccerAspire
    @AccerAspire 10 месяцев назад

    Thank you, this was amazing like your all videos.

  • @Gedeon-ox7yu
    @Gedeon-ox7yu 10 месяцев назад

    You are the best sir. Thank you!

  • @user-xb9tw5cp1s
    @user-xb9tw5cp1s 3 месяца назад

    O(nk)

  • @BOSS55
    @BOSS55 Год назад

    Thanks sir❤

  • @udaypatil3811
    @udaypatil3811 9 месяцев назад

    Sir maxSum should be checked after first for loop also

  • @kadismile114
    @kadismile114 11 месяцев назад

    Your Explanation is top notch , with the visuals and effects ... thanks

  • @cilivery
    @cilivery 10 месяцев назад

    Really amazed is this really for freee!!!
    Please continue like this

  • @akhilajohnson4626
    @akhilajohnson4626 11 месяцев назад

    Really well explained. Thankyou

  • @user-hh2oc7um1r
    @user-hh2oc7um1r Год назад

    beautiful elaboration of sliding window concept..

  • @sanasainath7758
    @sanasainath7758 6 месяцев назад

    Extraordinary ❤

  • @codingwithmx
    @codingwithmx Год назад

    Good explanation with illustration

  • @yoursvinayy
    @yoursvinayy Год назад

    bohot shi sir me yesi video dhundh rha tha

  • @kathiresansankaran4347
    @kathiresansankaran4347 11 месяцев назад

    Thanks really nice explanation and also visually explained. Any one can easily understand.

  • @tgmani4525
    @tgmani4525 10 месяцев назад

    @TAP ACADEMY
    I found the bug in the code
    The optimized code(sliding window) fails if my input array is
    10 10 10 5 2 3
    and k=3;
    expected output should be 30 (10+10+10)
    but the output for above code will be coming out to be 25(10 + 10 +5)
    this code wont work if the frst k length subarray have max sum so inorder to make it correct
    after the frst loop you should update the msum i.e
    msum=Math.max(wsum,msum);
    try this test case
    let me know if i m wrong!!

  • @prakash8921
    @prakash8921 8 месяцев назад

    Explain was good but we have not initialize the currentsum , in explaination u r saying that we have to substract the starting of ith element but u r adding there .

  • @MunniDivya
    @MunniDivya 6 месяцев назад

    thanks sir

  • @lingeshwarans8756
    @lingeshwarans8756 2 месяца назад

    24:59 you didn't add first window sum to mSum

  • @codingwithmx
    @codingwithmx Год назад +4

    8:48 is wrong with the 2nd loop of j, you have to update it to:
    int sum=0;
    int max =Integer.MIN_VALUE;
    int j=0;
    for(int i=0; i

    • @ignitealex8107
      @ignitealex8107 Год назад +1

      Thanks bruh ❤

    • @komalbharti7869
      @komalbharti7869 8 месяцев назад

      this code will give n^2 time complexity but in sliding window it should be 'n'

    • @tanujreddy8597
      @tanujreddy8597 7 месяцев назад

      no it will give us O(n)
      @@komalbharti7869

  • @abantichattopadhyay3183
    @abantichattopadhyay3183 3 месяца назад

    your explanation is such a nice one. I am one working profession and need to brush up all these algorithms for Interview Preparation. Please upload more examples of sliding window mechanism.

  • @pranithreddy
    @pranithreddy 8 месяцев назад

    Nice explanation

  • @ajaykumarpeddu
    @ajaykumarpeddu 11 месяцев назад +3

    Thank you! But your code ignores the first window max. So, mSum = wSum should be added before second loop.

  • @bharathbushan1150
    @bharathbushan1150 7 месяцев назад

    What if for the first time wsum is greater than all subarrays?
    It will skip the first hight sum of 0 to 2 array sizes
    for (int i= k; n > i; i++){
    wsum=wsum-a1[i-k]+a1[i];
    msum=Math.max(msum,wsum);
    }
    Here we are picking up msum
    after using msum=Math.max(msum,wsum)
    so that the first 0 to 2 index sum will be skipped if it has greater sum of all subarrays
    eg first wsum=52 instead of 42 ;
    can you check it please

  • @joyashamim2187
    @joyashamim2187 11 месяцев назад

    Great explanation👍

  • @mk6263
    @mk6263 Год назад +2

    Sir plz continue the lectures !! They are very helpful to us

  • @nenuanenenuane6645
    @nenuanenenuane6645 11 месяцев назад

    great video plz explain dynamic sliding window

  • @SharanyaBM-b7f
    @SharanyaBM-b7f Месяц назад

    i am not getting correct output for naive approach i am getting 113, i am not getting the what issue is. please let me know if anyone found in this code
    package javaprog;
    public class subarray_sum_nonNegative_integers {
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int arr[]= {2,9,31,-4,21,7};
    int maxsum=Integer.MIN_VALUE;
    int sum=0;
    int k=3;


    for(int i=0;i

  • @shubham_shubham
    @shubham_shubham 3 месяца назад

    what if i want to print the array which gave me that result???

  • @maharishicoding440
    @maharishicoding440 Год назад

    You teaches really well, Epic

  • @huzaifanaseer1484
    @huzaifanaseer1484 6 месяцев назад

    Great bro

  • @yourslovely5324
    @yourslovely5324 9 месяцев назад

    sir are you a brother of KL RAHUL....

  • @merlingrace6850
    @merlingrace6850 8 месяцев назад

    I understand this technique quite well now. No one can explain this technique in detail like you.

  • @muthukrishnan5727
    @muthukrishnan5727 Год назад

    im impressed with your lecture keep continue it you will achieve what you except

  • @HARI-iy5uv
    @HARI-iy5uv Год назад +1

    8:44 after updating mSum inside i loop then at the next line change cSum again to 0 cSum=0;
    Or else it adds up with the previous cSum