Minimum Size Subarray Sum | Leetcode

  Рет қаралды 31,591

Techdose

Techdose

Күн бұрын

Пікірлер: 38
@CostaKazistov
@CostaKazistov 2 жыл бұрын
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 2 жыл бұрын
Are you working as a SDE?
@techdose4u
@techdose4u 2 жыл бұрын
😀
@CostaKazistov
@CostaKazistov 2 жыл бұрын
@@leetcoder1159 Currently, no - but preparing for future interviews. Doing 4-5 Leetcode medium every day (434 so far).
@abhijitroy1958
@abhijitroy1958 2 жыл бұрын
@@CostaKazistov great sir
@oqant0424
@oqant0424 Жыл бұрын
@@CostaKazistov now?
@KingBobXVI
@KingBobXVI 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]; } }
@vivekkumaragrawal3963
@vivekkumaragrawal3963 Жыл бұрын
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
@nirajgujarathi6796
@nirajgujarathi6796 2 жыл бұрын
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 2 жыл бұрын
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; } }
@oqant0424
@oqant0424 Жыл бұрын
thanksssss a lot ............awesome explanation
@oladipotimothy6007
@oladipotimothy6007 2 жыл бұрын
The best explanation Sensei
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@vinayghadigaonkar8215
@vinayghadigaonkar8215 9 ай бұрын
Are you Still Teaching the DSA CRASH COURSE?
@VinothOfficialClub
@VinothOfficialClub 2 жыл бұрын
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..
@mtex448
@mtex448 2 жыл бұрын
I am not very good in time complexity theory, 5:36 how its become 10^10 and why should we go under
@nehasomani3446
@nehasomani3446 Жыл бұрын
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.
@syedaqib2912
@syedaqib2912 2 жыл бұрын
Well explained 🔥
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@sarthakgupta9858
@sarthakgupta9858 2 жыл бұрын
very nice explanation
@techdose4u
@techdose4u 2 жыл бұрын
Thanks :)
@PraveshGupta1992
@PraveshGupta1992 2 жыл бұрын
Just curious to know , would it work for [7, 7, 8, 8] and target is 2 ?
@techdose4u
@techdose4u 2 жыл бұрын
Yes. r-l+2 = 0-1+2 = 1 :)
@Pegasus02Kr
@Pegasus02Kr 2 жыл бұрын
Happy new year for you sir
@techdose4u
@techdose4u 2 жыл бұрын
Same to you 😀
@saivardhanpallerla9
@saivardhanpallerla9 2 жыл бұрын
Hi sir which app do u use for explaining
@programming3043
@programming3043 2 жыл бұрын
One note
@urrahman196
@urrahman196 Ай бұрын
21:45 cant find the next video? have you uploaded it?
@techdose4u
@techdose4u Ай бұрын
yes Please search it if not linked. Will add the link for it in description
@_benon
@_benon 2 жыл бұрын
i didnt understand what ur algorithm is
@tushararora672
@tushararora672 2 жыл бұрын
fee of course??
@devbhattacharya153
@devbhattacharya153 2 жыл бұрын
Sir one suggestion this video could be much shorter about of 15 mins although a great explanation thank you :)
@pijushbiswas4352
@pijushbiswas4352 Жыл бұрын
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 2 жыл бұрын
Sir your Instagram link not working
@techdose4u
@techdose4u 2 жыл бұрын
Need to check it :)
@abhishekmaldikar9704
@abhishekmaldikar9704 2 жыл бұрын
Instagram Id plz sir
Shortest Subarray with Sum at Least K | Leetcode 862
21:31
Techdose
Рет қаралды 37 М.
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 46 МЛН
PRANK😂 rate Mark’s kick 1-10 🤕
00:14
Diana Belitskay
Рет қаралды 12 МЛН
The Singing Challenge #joker #Harriet Quinn
00:35
佐助与鸣人
Рет қаралды 38 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 12 МЛН
Sliding Window Maximum | Leetcode
20:16
take U forward
Рет қаралды 262 М.
Minimum Size Subarray Sum - Leetcode 209 - Python
12:30
NeetCode
Рет қаралды 95 М.
Maximum Sum Circular Subarray | Leetcode #918
14:02
Techdose
Рет қаралды 86 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
Sliding Window Maximum | Leetcode #239
25:38
Techdose
Рет қаралды 54 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 833 М.
Kadane's Algorithm | Maximum Subarray Sum | Finding and Printing
20:09
take U forward
Рет қаралды 482 М.
Sliding Window Technique - Algorithmic Mental Models
36:45
Ryan Schachte
Рет қаралды 361 М.
L9. Binary Subarrays With Sum | 2 Pointers and Sliding Window Playlist
20:27
Trick-or-Treating in a Rush. Part 2
00:37
Daniel LaBelle
Рет қаралды 46 МЛН