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).
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.
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)."
Very well explained...two pointers from front concept - sliding window...!!
many places I am seeing that sliding window is being treated as dp problem
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.
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).
Both left and right points will only iterate list once. After the left items are popped up, they won't loop again, So still O(n)
Amazing solution. I was just very close to solving it but just could not think about the inner while loop
Thanks Nick for explaining in simple way
You made things looks so easy. thanks for the great video
Loved this solution and explanation
Thank you for creating this video 👍
glad i found this video, well explained. thank you so much.
crystal clear explanation
Amazing Solution!
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 :)
But 5,4 isn't a sub array. It's a sub sequence.
What happens if one of the input numbers was much larger than s, such as 1000, you would need to check if left !> i
u can never be rusty ... hahaha
I have got the rust from past 25 years
Very good solution. Thank a lot! :)
You shouldn't ignore your Apple updates
the solution is a little buggy. on line 12, he should add left
nice catch!
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.
good one, thx
nice explain!
good explanation!
Its called sliding window
Appreciate you!
Thanks for the video!!
Video is awesome!. Please create a video for implementing binary search using two pointers method for this problem
The time complexity for this one will be O(n log n), is that right?
A J even with binary search? If yes, do you know how to get to O(n log n)?
@@siobhanahbois binary search requires array to be sorted. That's not applicable in this problem.
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)."
This is O(nlogn). There is inner while loop.
@@ashwani4569 lol no, it's O(N)
Did any of you guys figure out the O(n log n) solution or did you find a video solving it in O(n log n) time?
@@siobhanahbois O(n log n) would be using binary search
O(n log n) is prefixSum + binary search
Beautiful 👏
Slidin' window
Its more like sliding window
wow thank you
great , i liked it
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;
}
```
can any one tell what is the time complexity ??
"Remind me tomorrow"
how one can think of this solution without looking at the soln
If u this type of question previously..😊
@@dashrathsinghkaviya it isn't related to the qn asked? if we visit his channel......will we get the ans??
That's an interesting question ⁉️
great vid
love you man
Isn't this slightly similar to sliding window concept ?
This is sliding window. The window can vary in size as it moves over the structure.
@@TheGianaJinx Basically a variable window-sized sliding window. Thanks for confirming !
wow
Other solution
awesome
HELP! How will the return statement look like in Python?
I got, it should be:
if result == math.inf: return 0
return result