LeetCode Minimum Size Subarray Sum Solution Explained - Java

  Рет қаралды 44,479

Nick White

Nick White

Күн бұрын

The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
Preparing For Your Coding Interviews? Use These Resources
--------------------
(My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
AlgoCademy - algocademy.com/?referral=nick...
Daily Coding Interview Questions - bit.ly/3xw1Sqz
10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
Follow Me on X/Twitter - x.com/nickwhitereal
Follow My Instagram - / nickwwhite
Other Social Media
----------------------------------------------
Discord - / discord
Twitch - / nickwhitettv
TikTok - / nickwhitetiktok
LinkedIn - / nicholas-w-white
Show Support
------------------------------------------------------------------------------
Patreon - / nick_white
PayPal - paypal.me/nickwwhite?locale.x...
Become A Member - / @nickwhite
#coding #programming #softwareengineering

Пікірлер: 66
@pl5778
@pl5778 4 жыл бұрын
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.
@faizanusmani2200
@faizanusmani2200 3 жыл бұрын
Amazing solution. I was just very close to solving it but just could not think about the inner while loop
@harshavardhanreddy7996
@harshavardhanreddy7996 3 жыл бұрын
Very well explained...two pointers from front concept - sliding window...!!
@deeproy2719
@deeproy2719 2 жыл бұрын
many places I am seeing that sliding window is being treated as dp problem
@CyberMew
@CyberMew 3 жыл бұрын
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).
@PeachHeartBlog
@PeachHeartBlog 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)
@sumeetsapla
@sumeetsapla 2 жыл бұрын
Thanks Nick for explaining in simple way
@SHASHANKRUSTAGII
@SHASHANKRUSTAGII 3 жыл бұрын
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.
@deepakbisht7764
@deepakbisht7764 2 жыл бұрын
You made things looks so easy. thanks for the great video
@yalansun4382
@yalansun4382 2 жыл бұрын
glad i found this video, well explained. thank you so much.
@suryanshrajdubey
@suryanshrajdubey 5 жыл бұрын
Thanks for the video!!
@edwardnewgate2198
@edwardnewgate2198 4 жыл бұрын
Amazing Solution!
@jaybabaofficial
@jaybabaofficial 2 жыл бұрын
Loved this solution and explanation
@sanketkoli8641
@sanketkoli8641 2 жыл бұрын
Very good solution. Thank a lot! :)
@chaoschao9432
@chaoschao9432 5 жыл бұрын
good one, thx
@alankuo2316
@alankuo2316 5 жыл бұрын
nice explain!
@jatinbhatoya8420
@jatinbhatoya8420 3 жыл бұрын
crystal clear explanation
@nandanimadhukar
@nandanimadhukar 3 жыл бұрын
good explanation!
@gregoryrobertson
@gregoryrobertson 8 ай бұрын
Thank you for creating this video 👍
@lifeofme3172
@lifeofme3172 4 жыл бұрын
Beautiful 👏
@OMFGallusernamesgone
@OMFGallusernamesgone 2 жыл бұрын
What happens if one of the input numbers was much larger than s, such as 1000, you would need to check if left !> i
@artsysoul1050
@artsysoul1050 2 жыл бұрын
can any one tell what is the time complexity ??
@abishekkachroo938
@abishekkachroo938 4 жыл бұрын
u can never be rusty ... hahaha I have got the rust from past 25 years
@pavithraradhakrishnan8229
@pavithraradhakrishnan8229 4 жыл бұрын
wow thank you
@kunalkheeva
@kunalkheeva Жыл бұрын
Appreciate you!
@adarsh9555
@adarsh9555 2 жыл бұрын
great , i liked it
@bhavyanayyer3391
@bhavyanayyer3391 3 жыл бұрын
how one can think of this solution without looking at the soln
@rajeevmohan9049
@rajeevmohan9049 3 жыл бұрын
If u this type of question previously..😊
@cpwithsundar
@cpwithsundar 2 жыл бұрын
@@dashrathsinghkaviya it isn't related to the qn asked? if we visit his channel......will we get the ans??
@aj9706
@aj9706 2 жыл бұрын
That's an interesting question ⁉️
@mnchester
@mnchester 2 жыл бұрын
great vid
@davegould4940
@davegould4940 4 жыл бұрын
Slidin' window
@akshitgarg09
@akshitgarg09 3 жыл бұрын
love you man
@sebastianbaptiste4905
@sebastianbaptiste4905 4 жыл бұрын
You shouldn't ignore your Apple updates
@harini3191
@harini3191 5 жыл бұрын
Video is awesome!. Please create a video for implementing binary search using two pointers method for this problem
@siobhanahbois
@siobhanahbois 4 жыл бұрын
The time complexity for this one will be O(n log n), is that right?
@siobhanahbois
@siobhanahbois 4 жыл бұрын
A J even with binary search? If yes, do you know how to get to O(n log n)?
@aj9706
@aj9706 4 жыл бұрын
@@siobhanahbois binary search requires array to be sorted. That's not applicable in this problem.
@zlzlinkinpark5337
@zlzlinkinpark5337 4 жыл бұрын
awesome
@arijitroy8390
@arijitroy8390 2 жыл бұрын
Its called sliding window
@harinijeyaraman8789
@harinijeyaraman8789 4 жыл бұрын
Isn't this slightly similar to sliding window concept ?
@TheGianaJinx
@TheGianaJinx 4 жыл бұрын
This is sliding window. The window can vary in size as it moves over the structure.
@harinijeyaraman8789
@harinijeyaraman8789 4 жыл бұрын
@@TheGianaJinx Basically a variable window-sized sliding window. Thanks for confirming !
@tensorflaw
@tensorflaw 2 жыл бұрын
"Remind me tomorrow"
@jakubk7158
@jakubk7158 3 жыл бұрын
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 :)
@dcodernz
@dcodernz 7 ай бұрын
But 5,4 isn't a sub array. It's a sub sequence.
@madhavram7138
@madhavram7138 4 жыл бұрын
HELP! How will the return statement look like in Python?
@madhavram7138
@madhavram7138 4 жыл бұрын
I got, it should be: if result == math.inf: return 0 return result
@raushanraj_99
@raushanraj_99 Жыл бұрын
@anoopkumar8732
@anoopkumar8732 3 жыл бұрын
the solution is a little buggy. on line 12, he should add left
@kevinwang3981
@kevinwang3981 2 жыл бұрын
nice catch!
@austinpereira9204
@austinpereira9204 Жыл бұрын
Its more like sliding window
@vk1618
@vk1618 4 жыл бұрын
Other solution
@siobhanahbois
@siobhanahbois 4 жыл бұрын
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)."
@ashwani4569
@ashwani4569 4 жыл бұрын
This is O(nlogn). There is inner while loop.
@arjunreddy3996
@arjunreddy3996 4 жыл бұрын
@@ashwani4569 lol no, it's O(N)
@siobhanahbois
@siobhanahbois 4 жыл бұрын
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?
@pavithraradhakrishnan8229
@pavithraradhakrishnan8229 4 жыл бұрын
@@siobhanahbois O(n log n) would be using binary search
@grandstarchief3226
@grandstarchief3226 4 жыл бұрын
O(n log n) is prefixSum + binary search
@Karthik__S_554
@Karthik__S_554 4 ай бұрын
wow
@joydeep_
@joydeep_ 2 ай бұрын
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; } ```
Self Taught Programmers... Listen Up.
11:21
Nick White
Рет қаралды 1 МЛН
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 44 МЛН
❌ Don't Run Behind 500 LEETCODE Problems ❌ Focus on QPCD
8:31
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 633 М.
LeetCode 22. Generate Parentheses
12:39
Nick White
Рет қаралды 81 М.
Minimum Size Subarray Sum | Leetcode #209
22:10
Techdose
Рет қаралды 30 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 560 М.
LeetCode 3Sum Solution Explained - Java
10:00
Nick White
Рет қаралды 196 М.
Опасность фирменной зарядки Apple
0:57
SuperCrastan
Рет қаралды 12 МЛН
low battery 🪫
0:10
dednahype
Рет қаралды 1,8 МЛН
Частая ошибка геймеров? 😐 Dareu A710X
1:00
Вэйми
Рет қаралды 5 МЛН