LeetCode Minimum Size Subarray Sum Solution Explained - Java

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

Very well explained...two pointers from front concept - sliding window...!!

harshavardhanreddy
Автор

great vid. I like how you explained the 2 pointers is not from start and end, but its both front the left. I think that concept is really helpful.

pl
Автор

Good explanation, I had the intuition to do sliding window using 2 pointers, but could not think of doing a while loop inside the forloop, and was fixated on moving both the right and left in the same loop, and was left figuring out why it is not working the way I want. ugh.. I think it was because I didn't want it to iterate so much, because it feels like O(n^2).

CyberMew
Автор

Amazing solution. I was just very close to solving it but just could not think about the inner while loop

faizanusmani
Автор

Thanks Nick for explaining in simple way

sumeetsapla
Автор

You made things looks so easy. thanks for the great video

deepakbisht
Автор

What happens if one of the input numbers was much larger than s, such as 1000, you would need to check if left !> i

OMFGallusernamesgone
Автор

glad i found this video, well explained. thank you so much.

yalansun
Автор

I dont know why, but i also thought of this method, before watching the video, my only issue is to develop the code. please guide me, i can see the way problem should be solved, but not able to code.

SHASHANKRUSTAGII
Автор

the solution is a little buggy. on line 12, he should add left<= i as another condition to ensure that left boundary doesn't cross the right boundary.

anoopkumar
Автор

u can never be rusty ... hahaha
I have got the rust from past 25 years

abishekkachroo
Автор

Video is awesome!. Please create a video for implementing binary search using two pointers method for this problem

harini
Автор

int[] arr= new int[]{5, 2, 2, 1, 1, 4}; target = 9 output = 3, should be 2 [5, 4], anyway this solution passes leetcode tests :)

jakubk
Автор

You shouldn't ignore your Apple updates

sebastianbaptiste
Автор

can any one tell what is the time complexity ??

artsysoul
Автор

This is O(n) right? What about the follow up question: "If you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log n)."

siobhanahbois
Автор

Isn't this slightly similar to sliding window concept ?

harinijeyaraman
Автор

how one can think of this solution without looking at the soln

bhavyanayyer
Автор

My O(1) solution in JS

```
function minSubArrayLen(arr, n) {

    if (!arr.length) return undefined

    let i=0
    let j=0
    let tmpSum = arr[i]
    let minLen = Infinity

    while(i < arr.length && j < arr.length){
        if (i === j){
            if (tmpSum >= n){
                minLen = Math.min(minLen, (j-i)+1)
                tmpSum-= arr[i]
                i++
                j++
                tmpSum+= arr[j]
                continue
            }

            if (tmpSum < n){
                j++
                tmpSum+= arr[j]
                continue
            }
        }

        if (tmpSum >= n){
            minLen = Math.min(minLen, (j-i)+1)
            tmpSum-= arr[i]
            i++
            continue
        }

        if (tmpSum < n){
            j++
            tmpSum+= arr[j]
            continue
        }

    }
    return minLen === Infinity ? 0 : minLen;
}
```

joydeep_