Minimum Size Subarray Sum | Leetcode

Sdílet
Vložit
  • čas přidán 12. 01. 2022
  • This video explains the minimum size subarray sum problem which is a variable size sliding window technique-based frequent interview problem. In this problem, I have explained the problem statement using easy-to-understand examples. I have explained the intuition for the algorithm using graph diagrams and then followed it up by a dry run and code explanation.
    CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
    ======================================PLEASE DONATE=============================
    🧡 SUPPORT OUR WORK: / techdose
    💚 UPI-ID: surya.kahar@ybl
    💞JOIN Membership: / @techdose4u
    ==============================================================================
    INSTAGRAM : / surya.pratap.k
    LinkedIn: / surya-pratap-kahar-47b...
    WEBSITE: techdose.co.in/
    TELEGRAM Channel LINK: t.me/codewithTECHDOSE
    TELEGRAM Group LINK: t.me/joinchat/SRVOIxWR4sRIVv5...
    =======================================================================
    USEFUL LINKS:
    🟠Must do TIPS to ACE Virtual Interview: • 🔴Must do Tips to ACE y...
    🟢Best strategy to excel your coding interview: • 🔴Best strategy to exce...
    🟡Get your dream job in 1 month: • 🔴Get your dream job in...
    🔵How to crack dream job in just 2 months: • How to crack dream job...
    🟣7 Days DSA plan: techdose.co.in/7-days-dsa-che...
    RELATED LINKS:
    CODE LINK: gist.github.com/SuryaPratapK/...

Komentáře • 36

  • @CostaKazistov
    @CostaKazistov Před 2 lety +24

    10^5 size for N^2 problem becomes 10^10 - very interesting observation you noted.
    I never realised that about computation limits, such as 10^8 you mentioned.
    Learned something new today.
    Great walkthrough of Leetcode 209 btw. Clear and on point.

    • @leetcoder1159
      @leetcoder1159 Před 2 lety

      Are you working as a SDE?

    • @techdose4u
      @techdose4u  Před 2 lety +1

      😀

    • @CostaKazistov
      @CostaKazistov Před 2 lety +2

      @@leetcoder1159 Currently, no - but preparing for future interviews. Doing 4-5 Leetcode medium every day (434 so far).

    • @abhijitroy1958
      @abhijitroy1958 Před 2 lety

      @@CostaKazistov great sir

    • @oqant0424
      @oqant0424 Před rokem

      @@CostaKazistov now?

  • @KingBobXVI
    @KingBobXVI Před 2 lety +2

    Excellent explanation of the problem overall, I kind of feel like the explanation of the +2 and inclusion of a second loop make it a little more confusing though, since a lot of time is spent explaining why it's +2 but that's a design choice rather than a necessary part of the overall algorithm. Time complexity is the same, but I feel like it's a little more straightforward (if more lengthy) like this:
    sum = nums[0];
    while (true) {
    int sub_array_size = right - left + 1;
    if (sum >= target) {
    if (sub_array_size == 1) return 1; // In the case where nums[i] >= target, you know the answer is the minimum. Early out prevents the left index going to the right of the right index.
    shortest = min(sub_array_size, shortest);
    sum -= nums[left];
    ++left;
    if (left == n) break;
    } else {
    ++right;
    if (right == n) break;
    sum += nums[right];
    }
    }

  • @oqant0424
    @oqant0424 Před rokem

    thanksssss a lot ............awesome explanation

  • @syedaqib2912
    @syedaqib2912 Před 2 lety +2

    Well explained 🔥

  • @oladipotimothy6007
    @oladipotimothy6007 Před 2 lety +1

    The best explanation Sensei

  • @sarthakgupta9858
    @sarthakgupta9858 Před 2 lety +1

    very nice explanation

  • @Pegasus02Kr
    @Pegasus02Kr Před 2 lety +1

    Happy new year for you sir

  • @PraveshGupta1992
    @PraveshGupta1992 Před 2 lety +2

    Just curious to know , would it work for [7, 7, 8, 8] and target is 2 ?

  • @mtex448
    @mtex448 Před 2 lety +1

    I am not very good in time complexity theory, 5:36 how its become 10^10 and why should we go under

    • @nehasomani3446
      @nehasomani3446 Před rokem

      Order is N^2 & max input size will be 10^5, so 2*5 = 10, therefore 10^10. 10^8, here 8/2 = 4, all inputs till 10^4 can be solved with it. Which means, if we go under 10^8, we can solve for further higher input size. I hope, this helps.

  • @saivardhanpallerla9
    @saivardhanpallerla9 Před 2 lety +2

    Hi sir which app do u use for explaining

  • @nirajgujarathi6796
    @nirajgujarathi6796 Před 2 lety

    found one modification, Correct me if I am wrong ! when , sum==target then no need to move left pointer because any ways it will lower the sum,
    In short if sum> target move left pointer towards right
    else if sum == taget update window size if it is smaller
    else if sum< target move right pointer

    • @KingBobXVI
      @KingBobXVI Před 2 lety

      With the way his logic is written, it just keeps the code consistent - since the "left" pointer is always over-shooting by one, so that once the sub-array is too small, he'll include the sub-array plus the previous element, so if the sub array is currently [1, 2, 4], he wants to iterate again to 1, [2, 4] because now he'll count the length of the sub array (2) and add 1 extra to account for the over-shoot.
      I think the way he did that actually complicates the verbal explanation significantly, for the sake of the video. Doing it with two loops is unnecessary, as you could just do a single loop along the lines of:
      while (not finished) {
      int sub_array_size = right - left + 1;
      if (total >= target) {
      minimum_sub_array_size = min(sub_array_size, minimum_sub_array_size);
      ++left;
      } else {
      ++right;
      }
      }

  • @VinothOfficialClub
    @VinothOfficialClub Před 2 lety

    For input target =7 and the array = {4,2,2,2,1,3}. how the solution find the correct answer based on your fix? the right pointer will reach end of an array and will tell the solution as 4.. not 2..

  • @vinayghadigaonkar8215
    @vinayghadigaonkar8215 Před 6 měsíci

    Are you Still Teaching the DSA CRASH COURSE?

  • @tushararora672
    @tushararora672 Před 2 lety

    fee of course??

  • @_benon
    @_benon Před 2 lety +1

    i didnt understand what ur algorithm is

  • @vivekkumaragrawal3963
    @vivekkumaragrawal3963 Před rokem +1

    class Solution {
    public:
    int minSubArrayLen(int target, vector& nums) {
    int len = nums.size(), ans = INT_MAX;
    int sum = 0;
    int left = 0,right = 0;
    while(right=target && left

  • @devbhattacharya153
    @devbhattacharya153 Před 2 lety

    Sir one suggestion this video could be much shorter about of 15 mins although a great explanation thank you :)

  • @pijushbiswas4352
    @pijushbiswas4352 Před 8 měsíci

    Could you help me understand, why won't this code work ?
    int minSubArrayLen(int target, vector& nums) {
    long long int s=0;
    int n=nums.size();
    for(int i=0;i

  • @abhishekmaldikar9704
    @abhishekmaldikar9704 Před 2 lety +1

    Sir your Instagram link not working