Minimum Size Subarray Sum | Google | Amazon | Easy Explanation | codestorywithMIK

Поділитися
Вставка
  • Опубліковано 2 лют 2025

КОМЕНТАРІ • 46

  • @UserUser-tn8tv
    @UserUser-tn8tv Рік тому +15

    Great Explanation

  • @wearevacationuncoverers
    @wearevacationuncoverers Рік тому

    One of the finest videos on this problem. This channel is a GEM

  • @BilluNo_1-c3j
    @BilluNo_1-c3j 18 днів тому

    solved without completing the whole video. thanks bhaiya, lot of improvement bcz of you!

  • @souravjoshi2293
    @souravjoshi2293 Рік тому +8

    Whenever you see a problem that involves finding contiguous sub-array (size or the sub-array itself) always consider using sliding window.

  • @vedanshbisht1309
    @vedanshbisht1309 Рік тому +2

    Great work, you have been a great help in maintaining streak. Thanks dude, kudos.

  • @daayush6654
    @daayush6654 Рік тому +2

    Best explanation in every video...
    Thanks a lot bhaiya🙏🏻
    Also in case interviewer bole ki -ve values bhi ho sakti hai array mae, toh prefix sum (hashing) use karenge na??

  • @souravjoshi2293
    @souravjoshi2293 Рік тому

    You are the best man. This channel is the ultimate

  • @dhruvsen7617
    @dhruvsen7617 11 місяців тому +1

    best explanation soo far
    thanks

  • @xiaoshen194
    @xiaoshen194 Рік тому +4

    90%+ comments from today only, goes on to show that u have grown alot 😅😂❤

  • @aws_handles
    @aws_handles Рік тому

    Binge watching this playlist 🙌

  • @floatingpoint7629
    @floatingpoint7629 Рік тому +3

    thanks for the explanation. i was able to solve it on my own.
    binary search solution if anyone is looking:
    basically you can try window of different size using binary search:
    function checkWindow(array, windowSize, target) {
    let sum = 0;
    for (let i = 0; i < windowSize; i++) sum += array[i]
    if (windowSize > array.length) return sum;
    let max = sum
    let [left, right] = [0, windowSize - 1];
    while (right < array.length) {
    sum -= array[left];
    left++;
    right++;
    if (right < array.length) sum += array[right];
    else break;
    max = Math.max(max, sum);
    }
    return max >= target
    }
    /**
    * @param {number} target
    * @param {number[]} nums
    * @return {number}
    */
    /**
    * @param {number} target
    * @param {number[]} nums
    * @return {number}
    */
    var minSubArrayLen = function (target, nums) {
    let [low, high] = [1, nums.length + 1];
    let ansPossible = false;
    while (low < high) {
    const mid = Math.floor((low + high) / 2);
    if (checkWindow(nums, mid, target)) {
    ansPossible = true;
    high = mid
    } else {
    low = mid + 1;
    }
    }
    return ansPossible ? high : 0;
    };

  • @FanIQQuiz
    @FanIQQuiz Рік тому

    Awesome and clean as always ❤

  • @thefinalfit
    @thefinalfit Рік тому

    Awesome and clean ❤❤❤

  • @AlishaKhan-ww3io
    @AlishaKhan-ww3io Рік тому

    Awesome explanation

  • @anuppatankar4294
    @anuppatankar4294 Рік тому +2

    Great Video👌🏻

  • @girikgarg8
    @girikgarg8 Рік тому

    Nice explanation

  • @shabananoor9423
    @shabananoor9423 Рік тому

    Best explanation ❤

  • @divyanshsagar
    @divyanshsagar Рік тому +1

    Nicely explained!

  • @simnidhnidh9122
    @simnidhnidh9122 5 місяців тому

    sir aap pls har playlist ki concept wali videos bhi dala karo🙏

  • @aatish5375
    @aatish5375 Рік тому +2

    Bhaiya...
    Can elaborate why LC follow up say ( try coding another solution of which the time complexity is O(n log(n)))

    • @codestorywithMIK
      @codestorywithMIK  Рік тому +2

      Hmm sure. Let me soon plan a video on that ❤️❤️

  • @jagadeeshp1163
    @jagadeeshp1163 Рік тому

    Imagine this man explaining Trading 🤑💸

  • @_PRANAYMATE
    @_PRANAYMATE 6 місяців тому

    U deserve more subscribers brother

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

    class Solution {
    public:
    int minSubArrayLen(int target, vector& nums)
    {
    int n=nums.size();
    int i=0;
    int j=0;
    long int tempSum=0;
    int ans=INT_MAX;
    while(j

  • @samratalam-p8i
    @samratalam-p8i 3 місяці тому

    Nice explanation, brother.
    But i have a question. Few days ago, I started your DP series. Now, I am starting this sliding window series.
    can we solve this using DP as the question is asked for minimum size?? How can we understand that it need to solve with sliding window or DP??
    take and skip then return min size of length? I have a little bit confusion to figure out how to solve this with dp or sliding window.

    • @YogeshwarGupta-r3u
      @YogeshwarGupta-r3u 2 місяці тому

      Whenever you see a problem that involves finding contiguous sub-array (size or the sub-array itself) always go for sliding window.

  • @abhinavsingh8090
    @abhinavsingh8090 6 місяців тому

    Whenever you see a problem that involves finding contiguous sub-array (size or the sub-array itself) always consider using sliding window.

  • @it.b.61.prashantsingh87
    @it.b.61.prashantsingh87 Рік тому

    Correct me plzz if I'm wrong, my question is, let's say if we have arr=(1, 1, 1, 4) and target = 4 then in this our T.C would be n^2 bcoz index j will iterate till end to become >=target i.e 4 now we will move index i from start to end to find the shortest sub array which is greater or equal to target. So in short my question is the worst time complexity for the first code is n^2

    • @Aakash-pc7kz
      @Aakash-pc7kz 3 місяці тому

      Probably a bit late,and you most probably know the answer by now, but still saying just in case
      No, it won't be n^2, it would be iterating the whole array almost twice in those such cases,not n*n times.
      O(2N) would be more like it, and as we ignore the constants as per conventions, it's considered as O(N) only.

  • @parthh1112
    @parthh1112 4 місяці тому

    class Solution {
    public:
    int minSubArrayLen(int t, vector& v) {
    int ans = 10000000 ,i = 0, j = 0, sum = 0, n = v.size();
    while(i < n){
    sum += v[i];
    while(sum >= t && j < n){
    ans = min(ans,i - j);
    sum -= v[j];
    j++;
    }
    i++;
    }
    return (ans == 10000000) ? 0 : ans+1;
    }
    };

  • @rvraghvender
    @rvraghvender 10 місяців тому +1

    Bihar me kahan se ho bhai?

  • @viditmohil7102
    @viditmohil7102 11 місяців тому

    Thanks men

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

    Bhaiya, ajkal kahan google amazon e sab puchti hai 🤧🤧. Ajkal to 4 - 5 LPA offer karne wale company bhi leetcode hard puchti hai, aur ajkal to MAANG company apne interview main bhi CP ke jaise questions puchte hai, nehi to leetcode hard, jo CP ke liye hi hote hai 🥹

  • @prathamsarraf6999
    @prathamsarraf6999 5 місяців тому +1

    It is kind of 2 pointer approch and less about sliding window

  • @gurudassulebhavikar
    @gurudassulebhavikar Рік тому

    n logn ka solution to reh hi gaya bhai