Minimum Size Subarray Sum - Leetcode 209 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 72

  • @kartiksoni825
    @kartiksoni825 2 ปีที่แล้ว +60

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

  • @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.

  • @spirner669
    @spirner669 2 ปีที่แล้ว +8

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

  • @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.

  • @elvinjafarli6257
    @elvinjafarli6257 2 ปีที่แล้ว +1

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

  • @summisahani6415
    @summisahani6415 หลายเดือนก่อน

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

  • @metin4yt
    @metin4yt 2 ปีที่แล้ว +3

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

  • @studbud-qw3yo
    @studbud-qw3yo 8 หลายเดือนก่อน

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

  • @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?

  • @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 🙏

  • @yash-uy5ym
    @yash-uy5ym 4 หลายเดือนก่อน

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

  • @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

  • @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

  • @saileshsriram3295
    @saileshsriram3295 ปีที่แล้ว

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

  • @serene7560
    @serene7560 4 หลายเดือนก่อน

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

  • @lingxu9697
    @lingxu9697 2 ปีที่แล้ว

    Love you NC, best coding channel ever...

  • @slai2389
    @slai2389 ปีที่แล้ว

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

  • @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.

  • @GenerationX186
    @GenerationX186 2 ปีที่แล้ว

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

  • @budiman-kr5ug
    @budiman-kr5ug 8 หลายเดือนก่อน

    so many people are helped because of you

  • @RachelDong-y4s
    @RachelDong-y4s 14 วันที่ผ่านมา

    expend right until success, shrink left until fail

  • @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)?

  • @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.

  • @user-ft1rj5jh3n
    @user-ft1rj5jh3n 2 ปีที่แล้ว +1

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

  • @MISIUYT
    @MISIUYT 2 ปีที่แล้ว +2

    Solving this on my own took way too long :)

  • @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

  • @ngneerin
    @ngneerin 2 ปีที่แล้ว

    Beautiful solution

  • @howardlam6181
    @howardlam6181 หลายเดือนก่อน

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

  • @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

  • @pradeepranjan1309
    @pradeepranjan1309 2 ปีที่แล้ว

    great... You makes coding fun

  • @thepriestofvaranasi
    @thepriestofvaranasi หลายเดือนก่อน +1

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

  • @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)

  • @shamanthsham513
    @shamanthsham513 2 ปีที่แล้ว

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

  • @adnanhowlader143
    @adnanhowlader143 2 ปีที่แล้ว +1

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

  • @leetcodeespanol59
    @leetcodeespanol59 2 ปีที่แล้ว

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

  • @aleksandrajovanovic2631
    @aleksandrajovanovic2631 7 หลายเดือนก่อน

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

  • @taimurshah5956
    @taimurshah5956 2 ปีที่แล้ว

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

  • @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 !

  • @Nick-uo2bi
    @Nick-uo2bi 2 ปีที่แล้ว +3

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

  • @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

  • @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.

  • @setiyakitchen
    @setiyakitchen 3 หลายเดือนก่อน

    what if the array contains negative too?

  • @yashpathak9285
    @yashpathak9285 2 ปีที่แล้ว

    When are we getting a series for System Design ?

    • @NeetCode
      @NeetCode  2 ปีที่แล้ว +1

      Hopefully next month!

  • @trungduong8225
    @trungduong8225 5 หลายเดือนก่อน

    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 5 หลายเดือนก่อน +1

      oh it's greater than or equal to

    • @waltairwhite821
      @waltairwhite821 หลายเดือนก่อน

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

  • @weiyaoli6977
    @weiyaoli6977 2 ปีที่แล้ว

    amazing! love it

  • @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.

  • @12.aryankumar45
    @12.aryankumar45 2 ปีที่แล้ว +1

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

  • @vijethkashyap151
    @vijethkashyap151 ปีที่แล้ว

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

  • @numberonep5404
    @numberonep5404 2 ปีที่แล้ว

    Very nice content as usual :3 !!

  • @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).

  • @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

  • @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.

  • @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