Minimum Size Subarray Sum - Leetcode 209 - Python

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

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

  • @kartiksoni825
    @kartiksoni825 2 года назад +62

    This is probably the best Leetcode channel on the internet. Thank you so much for the invaluable content. Your drawing explanations are gold!

  • @spirner669
    @spirner669 2 года назад +8

    after watching so many problems done by u. For this problem i've came up with exactly the same solution

  • @rongrongmiao3018
    @rongrongmiao3018 2 года назад +7

    Please do a video on the follow up question of this question: what do we do if there are negative numbers in the array. Thanks.

  • @nikhilvecha6192
    @nikhilvecha6192 2 года назад +13

    Many thanks to you sir, you're actually helping a lot of people by solving these questions

  • @udaykulkarni5639
    @udaykulkarni5639 2 года назад +4

    This guy is absolute Legend and has ability to make complicated problems look easy! Thanks man :) Keep up the good work.

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

    Probably the most precise explanation. Thanks a lot. Keep posting.

  • @elvinjafarli6257
    @elvinjafarli6257 2 года назад +1

    Much appreciated, the explanation is way better than any Leetcode solution provided.

  • @abhishekpawar8458
    @abhishekpawar8458 2 года назад +20

    What a coincidence, I was just solving the same problem on Lintcode !
    Thanks a lot for the upload, I have an upcoming google interview

  • @yash-uy5ym
    @yash-uy5ym 4 месяца назад

    I thought this question had some trick in it but it's only a sliding window
    Great explanation ❤

  • @studbud-qw3yo
    @studbud-qw3yo 9 месяцев назад

    i was kinda confused on why you were not using if statement thanks for clearing my doubt you are a legend

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

    This was a pretty complicated problem. Thanks a lot for helping me understand it.

  • @israaezzat2353
    @israaezzat2353 2 года назад

    Really feel relaxed when i am looking for a solution of a problem on youtube and find your vedio ❤❤

  • @cutiex7357
    @cutiex7357 2 года назад +2

    Every time when I hear "Hi everyone welcome back" I'm excited!!!

    • @T3Deye
      @T3Deye 2 года назад

      mate you are not a real person

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

    Thank you, I was struggling to this question until I found your video

  • @RachelDong-y4s
    @RachelDong-y4s 24 дня назад

    expend right until success, shrink left until fail

  • @lingxu9697
    @lingxu9697 2 года назад

    Love you NC, best coding channel ever...

  • @anmolmittal5689
    @anmolmittal5689 2 года назад +9

    You are a good person, helping us in programming 😊.
    How do you build such algos ?
    Plz give us a path to stick to master DSA 🙏

  • @GenerationX186
    @GenerationX186 2 года назад

    Love your videos. They're so helpful. Always leave more informed and with one more approach than before playing your video.

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

    1590 is basically this problem but needs to be equal not greater than

  • @metin4yt
    @metin4yt 2 года назад +3

    What would be the solution if there would be negative numbers in the array?

  • @budiman-kr5ug
    @budiman-kr5ug 8 месяцев назад

    so many people are helped because of you

  • @6priyanshu
    @6priyanshu 2 года назад +1

    my first comment ever on YT, you are an inspiration. please keep creating such awesome content !! you are helping community, thank you !

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

    What do you make of the follow-up question, which asks us to come up with a worse solution that the sliding window one we already came up with?

  • @adnanhowlader143
    @adnanhowlader143 2 года назад +1

    daily one problem from your channel,,thats the challenge I took

  • @pradeepranjan1309
    @pradeepranjan1309 2 года назад

    great... You makes coding fun

  • @MISIUYT
    @MISIUYT 2 года назад +2

    Solving this on my own took way too long :)

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

    When neet say things like: "well this is easy solution" or "this is just a standard xyz algo" just makes a dumbhead like me feel even dumber.

  • @ngneerin
    @ngneerin 2 года назад

    Beautiful solution

  • @leetcodeespanol59
    @leetcodeespanol59 2 года назад

    Gracias por el video otra vez! Gran ayuda que esta poniendo en youtube!

  • @Nick-uo2bi
    @Nick-uo2bi 2 года назад +3

    Please create a playlist for DSA and DP in python beacause there isn't any on RUclips yet.....it will help thousand of ppl.

  • @balamurali8980
    @balamurali8980 2 года назад

    Can you please help in solving the question - 68. Text Justification. There is no explantation even in leetcode, please. Thank you so much for your valuable videos.

  • @akshaibaruah1720
    @akshaibaruah1720 2 года назад +4

    This solution (optimized) was pretty easy to come up with. But can you make a video on the follow up of this question i.e. do it in O(nlogn)

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

    I was thinking about an algorithm that would leverage sorting the nums in reverse order and I kinda feel like it could be possible

  • @user-ft1rj5jh3n
    @user-ft1rj5jh3n 2 года назад +1

    Hi neetcode! Could you post a video on Knight Dialer? It would mean a lot! Thank youu

  • @jugsma6676
    @jugsma6676 2 года назад

    Thank you,
    This would be my approach:
    import sys
    def min_sub_array(target, nums):
    l = 0
    r = 1
    if target == nums[l]: return 1
    total = nums[l] + nums[r]
    min_len = sys.maxsize
    while r >= l and r < len(nums):
    if total == target:
    min_len = min_len if min_len < r-l+1 else r-l+1
    l = l+1
    r = r+1
    total = sum(nums[l:r + 1])
    elif total > target:
    min_len = min_len if min_len < r-l+1 else r-l+1
    l = l+1
    total = sum(nums[l:r+1])
    else:
    r = r+1
    total = sum(nums[l:r+1])
    min_len = 0 if min_len == sys.maxsize else min_len
    return min_len

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

    can we check if r-l+1= 1 inside the while loop and return 1 if that's the case?

  • @hype-r3076
    @hype-r3076 10 месяцев назад

    What if the array contains all elements greater than the target then wouldn’t the time complexity run in O(n^2)?

  • @shamanthsham513
    @shamanthsham513 2 года назад

    Isn't brute force solution's time complexity is O(n^2 logn) /O(n^3) ?

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

    How do you do it so easily dude. I spent hours clueless trying to come up with stupid solutions.

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

    @neetcode sir .in this question follow up is to solve this by binary search....please help me to do using binary search...atleast please give a hint how we can solve using binarysearch..please

  • @weiyaoli6977
    @weiyaoli6977 2 года назад

    amazing! love it

  • @procon4
    @procon4 2 года назад

    Is there a faster approach where you start at the index of the largest number in the list rather than the first?

    • @zolopane117
      @zolopane117 2 года назад

      I don’t think that works. Imagine the input array in example 1 was [2, 3, 1, 2, 3, 4] instead (basically just swapping the last two elements). If you jumped to the largest element, you’d hit the end of the list before ever reaching the max. It’s possible to add a conditional to check both sides of the max, but that might run into issues if you had an input like this: [2, 3, 2, 1, 1, 4, 1]

    • @procon4
      @procon4 2 года назад

      @@zolopane117 yeah I was thinking you’d expand outward from the largest item.

  • @12.aryankumar45
    @12.aryankumar45 2 года назад +1

    First here today ig. Thank you so much for these videos .

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

    what if the array contains negative too?

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

    how can we do this with one passage through array??

  • @numberonep5404
    @numberonep5404 2 года назад

    Very nice content as usual :3 !!

  • @yashpathak9285
    @yashpathak9285 2 года назад

    When are we getting a series for System Design ?

    • @NeetCode
      @NeetCode  2 года назад +1

      Hopefully next month!

  • @plontulublalulu
    @plontulublalulu 2 года назад

    wait, they got rid of the "contiguous" part on the problem. Is it still contiguous?

    • @nikhil_a01
      @nikhil_a01 2 года назад +1

      Yes, it's still contiguous. A subarray is by definition contiguous.
      You can test it on LeetCode too. If they accepted non-contiguous elements then the solution to nums = [5, 1, 2, 3], target = 7 should be 2. Because [5] and [2] sum to 7. But their expected answer is 3 because [5, 1, 2] is the only contiguous subarray that sums to >= 7.

  • @taimurshah5956
    @taimurshah5956 2 года назад

    What software do you use to draw? And how do you record it?

  • @vishwanathanr2851
    @vishwanathanr2851 2 года назад

    How many problems you solve per day ❤️

    • @MISIUYT
      @MISIUYT 2 года назад +1

      he said at least one, but sometimes more depending on the day.

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

    hey thanks for the great video, but I'm having a problem. I implemented the similar idea with python then submit, but it got error with the input of [1,2,3,4,5]. It said expected "3" but I dont see any valid window with that size. Can anyone help, thanks!

    • @trungduong8225
      @trungduong8225 6 месяцев назад +1

      oh it's greater than or equal to

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

      @@trungduong8225 lol thanks dude..
      i feel dumb now

  • @programming3043
    @programming3043 2 года назад +1

    Can anyone explain why its not O(n²)

    • @chenyan4444
      @chenyan4444 2 года назад

      Same question here.

    • @nikhil_a01
      @nikhil_a01 2 года назад +1

      Why would it be O(N^2)?
      The right pointer iterates through the entire array doing O(1) work each time. That's O(N). And the left pointer also iterates through the entire array in the worst case, doing O(1) work each time. That's also O(N). So the overall time is O(N).

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

    Can anybody help me with understanding the complexity of the solution coded here?

  • @faisalabdulkadir9439
    @faisalabdulkadir9439 2 года назад +1

    Good day sir , I appreciate all the work u are doing , pls sir can u pls look at the increasing in order search tree question 897, I’m having a hard time understanding the recursion process used ,thank u sir

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

    Is this a joke. how am i supposed to come up with it during the interview. anyway, great video as always.

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

      Practice. Do multiple sliding window problems and you'll be able to recognise the pattern. These are PHD level dissertations and you can't come up with your own if you haven't done similar problems before.

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

    any one wants to practise please comment

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

    bruh we can almost hear you, please decrease your voice volume a bit more