Shortest Subarray with Sum at Least K | Already Studied Concept | Leetcode 862 | codestorywithMIK

  Рет қаралды 10,790

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер
@anukulsahu
@anukulsahu Ай бұрын
A good example of how including negative people in your life affects your mental health, from leetcode
@madhubabu3482
@madhubabu3482 Ай бұрын
Good one sir, I solved 850+ questions on leetcode with 350+ days streak Still selected for 3.5LPA in TCS Feeling sad but i am still motivated and consistent that i will do Big someday Thanks for posting videos regularly
@gui-codes
@gui-codes Ай бұрын
congrats man. don't worry it's the start. you will get to your goal. have faith and keep grinding.
@guddukumar-v8z5l
@guddukumar-v8z5l Ай бұрын
bhai konse college se ho.
@anshror2583
@anshror2583 Ай бұрын
Hey can you can share your linkedin ID
@anshror2583
@anshror2583 Ай бұрын
Congrats man celebrate every moment although your output is not equal to your effort but soon you will get to your goal
@malvado8267
@malvado8267 Ай бұрын
contest rating kitna hai?
@rishabhray7295
@rishabhray7295 Ай бұрын
you are doing good job and without any fumble and crystal clear in all your videos
@Aditya-qx7nf
@Aditya-qx7nf Ай бұрын
Thnx bro, loved the approach. Solved the medium level one without thinking but couldn't solve when negtive numbers were involved
@wearevacationuncoverers
@wearevacationuncoverers Ай бұрын
perfection at its peak. you are amazing
@KajalSinghshine
@KajalSinghshine Ай бұрын
0:45 yes sir and these are those people who are themselves going nowhere..
@codestorywithMIK
@codestorywithMIK Ай бұрын
Indeed 🙏
@varunpalsingh3822
@varunpalsingh3822 Ай бұрын
Aaj monotonic stack/queue/deque ki need samaj ayi, thanks ❤
@gui-codes
@gui-codes Ай бұрын
legend is here. i solved leetcode-209 as well. thanks to you
@TanmayMankar-26
@TanmayMankar-26 Ай бұрын
Awesome explanation
@thefinalfit
@thefinalfit Ай бұрын
Was waiting. Thanks a lot
@evigamer1136
@evigamer1136 Ай бұрын
Brother your explanation is awesome keep it up bro
@piyush0mandloi
@piyush0mandloi Ай бұрын
thank you sir . awesome explanation.
@manavrajthakor8175
@manavrajthakor8175 Ай бұрын
This was my approach for this question but failed to handle negative values : class Solution { public: int shortestSubarray(vector& nums, int k) { int len = INT_MAX; int l = 0; int r = 0; int n = nums.size(); int sum = 0; while(r < n) { sum+=nums[r]; while(sum >=k) { sum-=nums[l]; len = min(len,r-l+1); l++; } r++; } if(len==INT_MAX) { return -1; } return len; } };
@sanebrain3083
@sanebrain3083 Ай бұрын
i eactly got stuck at the -ve part part the test was exactly the i was stuck 84 -37 32 40 95
@Shubhammi1100
@Shubhammi1100 Ай бұрын
waiting for this video
@FanIQQuiz
@FanIQQuiz Ай бұрын
Awesome 🙌
@jscoder-r7z
@jscoder-r7z Ай бұрын
motivation padh ke maza aa gaya
@38shashwatshukla89
@38shashwatshukla89 Ай бұрын
amazing sir
@gauravbanerjee2898
@gauravbanerjee2898 Ай бұрын
Thanks a lot bhaiya ❤❤
@HarmanSingh-nw6ix
@HarmanSingh-nw6ix Ай бұрын
good afternoon bhaiya ..
@gui-codes
@gui-codes Ай бұрын
Anyone need more clarity on why first 84 was removed from deque as soon as we saw a dip from 84 to 47. Here is more points to get more clarity. nums = {84, -37, 37, 40, 95} cumSum = {84, 47, 84, 124, 219} Let's say you are index j = 4, where cumSum is 219 >= k Now, you want to shrink the window. If you notice if you shrink and remove index 0 from left side i.e. 84 Then subarray sum from index 1 to index 4 will be = cumSum[j] - cumSum[0] = 219 - 84 = 135 But if you notice, even if you shrink the window further and remoce index 0 and index 1 from the window, you get the same answer= cumSum[j] - cumSum[2] = 219 - 84 = 135 So there was no point of keeping the first 84 because there was a dip from 84 to 47 and we can get sum >= k further also which will be even shorter subarray. Hope this is clear. Thanks to MIK for improving my thinking skills.
@harsh5720
@harsh5720 Ай бұрын
Can't we keep count of negative no. We encounter in window if there is negative no. That means there is chance that sum would get increased hence we can shift the window towards left ..
@rnehacodes
@rnehacodes Ай бұрын
Hi Mazhar. Thanks for the video. @codestorywithMIK Just a *small suggestion/request* to add a unique hashtag or keyword to your video title. When stuck with any leetcode question, i often look for your explanation video but due to long channel name it is slightly cumbersome to find the video quickly. As of now, i personally use your git repo to find code snippets and related explanation videos. But if possible, you can include a simple and quick hashtag to your video or any content in general so that we can find your videos quickly. This might help in expanding the reach of channel too as more and more viewers will do organic searches for your hashtag. Rest, keep doing the great work! God bless you!
@codestorywithMIK
@codestorywithMIK Ай бұрын
Hi there, I appreciate your feedback. Thank you so much. Let me try to add #MIK from now onwards. That might help ❤️🙏
@sumit_verma77
@sumit_verma77 Ай бұрын
[80 -30 50] k = 100 so how we can remove 80? it needs to be added in subarray then only we will be able to make 100? I didn't get that part
@codestorywithMIK
@codestorywithMIK Ай бұрын
As soon as j reaches 50, the cumulativeSum[j] will become = 100 And if you notice I have put a check that if cumulativeSum[j] >= k result = min(result, j+1) So result becomes = 3 So we won’t miss that case also where we reach sum >= 100 here in this example That was a good example. Thanks for this Qn ❤️🙏
@ShardulPrabhu
@ShardulPrabhu Ай бұрын
I had same question but got ans thanks
@s09021994
@s09021994 Ай бұрын
Hey sorry but how will [10,80,-30,50] work with k=100?
@alokkumar4419
@alokkumar4419 Ай бұрын
​@@s09021994 The deque will have values 0, 2, 3 as index because cumulative sum for 0, 2 and 3 index is 10, 60, and 110 respectively.. So the while loop used for reducing the size will manage this scenario.
@sajalchouksey
@sajalchouksey Ай бұрын
You explain great, But plz try to upload solutions of Leetcode contest at least of only EASY level
@codestorywithMIK
@codestorywithMIK Ай бұрын
Yes definitely. Actually i always travel during weekends to take break. I will try to upload them as well. Thank you for your kind words ❤️🙏
@jeehub041
@jeehub041 Ай бұрын
Ist view as always ❤❤
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Ай бұрын
First 🎉❤
@Sumit-wy4zp
@Sumit-wy4zp Ай бұрын
sir please "sweep line " algorithm pe video banaiye..🥺🥺🥺🥺
@rickdutta942
@rickdutta942 Ай бұрын
Solved the medium after watching your video but stuck on this problem 😔😔
@d_Editzz4003
@d_Editzz4003 Ай бұрын
can anyone explain how would i know whether to apply sliding window or not according to the questions
@harjotanand834
@harjotanand834 Ай бұрын
So sir ...You mean to say that suppose we wish to move ith pointer ...its possible that cumSum is larger or greater and we cannot obtain sum >= k and also if we get there maybe some smaller cumSum ahead of i and if we subtract it with that lesser cumSum we may get sum >= k ..SO we keep track of previous elements in increasing order so that we have min or less element to check with ( which gives higher chances of getting sum >= k ) and then for larger and again larger so as to see if we can shrink ... Am I Correct ?? IF NOT please correct sir 🙏🏻🙏🏻
@gui-codes
@gui-codes Ай бұрын
Are aise samjho. nums = {84, -37, 37, 40, 95} cumSum = {84, 47, 84, 124, 219} Let's say you are index j = 4, where cumSum is 219 >= k Now, you want to shrink the window. If you notice if you shrink and remove index 0 from left side i.e. 84 Then subarray sum from index 1 to index 4 will be = cumSum[j] - cumSum[0] = 219 - 84 = 135 But if you notice, even if you shrink the window further and remoce index 0 and index 1 from the window, you get the same answer= cumSum[j] - cumSum[2] = 219 - 84 = 135 So there was no point of keeping the first 84 because there was a dip from 84 to 47 and we can get sum >= k further also which will be even shorter subarray. Hope this is clear
@harjotanand834
@harjotanand834 Ай бұрын
@gui-codes yaa bro got that thanks
@gamersgame43
@gamersgame43 Ай бұрын
I just exactly stuck on this problem test case 51 / 98 testcases passed, which was shown in 2:57, just tried 1hr to figure out how can I use slidiing window, then only came here
@yatheshtpoonia9225
@yatheshtpoonia9225 Ай бұрын
i was able to do the question you asked in the video but even after that aaj wala solution chamka nahi
@anjumaurya5603
@anjumaurya5603 Ай бұрын
Can we solved it using brute force?
@pradeepranjan8226
@pradeepranjan8226 Ай бұрын
yes, but it will only give TLE. But you must start with Brute force (82/98 testcase passed) Java Brute force: class Solution { public int shortestSubarray(int[] nums, int k) { int len = 10000000; //any max number //check each subarray for(int i = 0; i < nums.length; i++){ for(int j = i; j < nums.length; j++){ int sum = 0; //window sum for(int s = i; s = k){ len = Math.min(len, j - i + 1); } } } return len == 10000000 ? -1 : len; } }
@RishabhChatterjee-fg2gz
@RishabhChatterjee-fg2gz Ай бұрын
Bhaiya mene bhi yehi example pe atak gya tha
@hellsterkun8764
@hellsterkun8764 Ай бұрын
Can we solve this question by not using dequeue?
@3mbgaming444
@3mbgaming444 Ай бұрын
First comment
@StudentjatinJatin
@StudentjatinJatin Ай бұрын
(1574. Shortest Subarray to be Removed to Make Array Sorted ) bhaiya please isa monotonic sa bna do ma 3 din sa try kar ra 🙂🙂
@DarkDragon-bz6qp
@DarkDragon-bz6qp Ай бұрын
Why using Dequeue cant we use Stack here?As we can get increasing Sequence using Stack..What is the special advantage of using Double ended Queue ?it only allows insertion and deletion from both start and end
@gui-codes
@gui-codes Ай бұрын
The only benefit is that you can shrink the window from left side which is the requirement of this problem. You can pop from left side and push from right side.
@DarkDragon-bz6qp
@DarkDragon-bz6qp Ай бұрын
@gui-codes Yeah got it thanks..Saw his previous video on power subarrays part 1
@ex.comfy_error
@ex.comfy_error Ай бұрын
sir black screen pe code kia kr ye pls ! anyways ,thanks for valuable effort
@codestorywithMIK
@codestorywithMIK Ай бұрын
Sure definitely. ❤️ Next video in black screen
@TanmayMankar-26
@TanmayMankar-26 Ай бұрын
-28 81 -20 28 -29 plz explain me this testcase
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Ай бұрын
my solution without using dq. public int shortestSubarray(int[]nums,int k){ int n=nums.length; long[]prefix =new long[n+1]; for(int i=0;i
@mananatal5644
@mananatal5644 Ай бұрын
bhaiya please use dark theme in vs code😅😅
@codestorywithMIK
@codestorywithMIK Ай бұрын
Yes definitely. Actually i was travelling back home and hence forgot to switch to dark mode in rush. ❤️🙏
@mananatal5644
@mananatal5644 Ай бұрын
@@codestorywithMIKthanks 😀 also please make video on infix to postfix and prefix conversion using stack
@dibbodas4116
@dibbodas4116 Ай бұрын
bhaiya why 84 is irrelevant i didnt understand that part
@gui-codes
@gui-codes Ай бұрын
Are aise samjho. nums = {84, -37, 37, 40, 95} cumSum = {84, 47, 84, 124, 219} Let's say you are index j = 4, where cumSum is 219 >= k Now, you want to shrink the window. If you notice if you shrink and remove index 0 from left side i.e. 84 Then subarray sum from index 1 to index 4 will be = cumSum[j] - cumSum[0] = 219 - 84 = 135 But if you notice, even if you shrink the window further and remoce index 0 and index 1 from the window, you get the same answer= cumSum[j] - cumSum[2] = 219 - 84 = 135 So there was no point of keeping the first 84 because there was a dip from 84 to 47 and we can get sum >= k further also which will be even shorter subarray. Hope this is clear
@xboy2374
@xboy2374 Ай бұрын
sir leetcode ko dark mode kara karo plz
@codestorywithMIK
@codestorywithMIK Ай бұрын
Yes actually i was travelling back to home. In rush i missed to make dark theme. Apologies for inconvenience. Will take care from next video ❤️🙏
@jimmyaghera1897
@jimmyaghera1897 Ай бұрын
why use deque why not just queue ?
@codestorywithMIK
@codestorywithMIK Ай бұрын
In que you won’t be able to pop from behind to maintain monotonic nature. Notice that in order to make it increasingly monotonic we will have to pop from behind. Also to shrink the window, we need to pop from front also. So deque provides both functionalites
@akashkumarmaurya2319
@akashkumarmaurya2319 Ай бұрын
majo me bhai ?
@AdarshShukla-nl1ij
@AdarshShukla-nl1ij Ай бұрын
bhai java me code chahiye tha
@codestorywithMIK
@codestorywithMIK Ай бұрын
Please check the github link in the description . It has java code too ❤️
@abhaysharmafitness
@abhaysharmafitness Ай бұрын
late ho gaya thoda
@codestorywithMIK
@codestorywithMIK Ай бұрын
Apologies for inconvenience. I am exploring Hyderabad this long weekend and hence the delay. ❤️🙏
@mehranahmed3612
@mehranahmed3612 Ай бұрын
@@codestorywithMIK Dont even be sorry about it. I started solving daily challenges because of you posting the solutions later.
18 mathematicians break my secret santa method
31:49
Stand-up Maths
Рет қаралды 252 М.
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
Shortest Subarray with Sum at Least K | Leetcode 862
21:31
Techdose
Рет қаралды 38 М.
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 138 М.
Real usage of Math in Software Engineering
13:57
Roman V.
Рет қаралды 2,3 М.
Shortest Subarray with Sum at Least K - Leetcode 862 - Python
27:57
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН