At 1:45 , we have one more subarray of sum 9, i.e 1, 3, 2, 3
@AyushiSharmaDSA2 жыл бұрын
Yes, that I missed, in later part of video, we did found out. Pinning your comment so that others can know. Thanks :)
@devendratumu17042 жыл бұрын
the way you are explaining the problem is very good keep doing more
@AyushiSharmaDSA2 жыл бұрын
Thank you Devendra :)
@rajdave73572 жыл бұрын
Yes, She is awesome
@vaibhavgoel77502 жыл бұрын
Yes, she is excellent in explanation.
@AyushiSharmaDSA2 жыл бұрын
@@vaibhavgoel7750 @Raj dave thanks guys🥺😄
@rishalirishu58332 жыл бұрын
Oh god...I tried soln from so many channels but unable to understand....Finally you are back wth the solution
@AyushiSharmaDSA2 жыл бұрын
Thank you Rishali, glad it was helpful :)
@rohangangwar66042 жыл бұрын
after doing some questions i observed one thing that most of the questions on subarrays can be solved using maps with optimisation.
@AyushiSharmaDSA2 жыл бұрын
Yes :)
@RajeshS-n2j3 ай бұрын
like the reasoning and how you explained why sliding window and other 2 pointer approach will not work in this case, thanks for pointing it out. nice video. 😀
@AyushiSharmaDSA3 ай бұрын
Glad it was helpful! thank you :)
@CodeWithSeenu3 ай бұрын
Thanks a million.. this explanation solved lots of doubts
@AyushiSharmaDSA3 ай бұрын
welcome, glad it helped :)
@alienx23672 жыл бұрын
Initial I thought of doing by sliding window later realised it consists of negative integers , This is a good approach also We can just do m[0] = 1 , so we don't have to if sum == k then count++ class Solution { public: int subarraySum(vector& nums, int k) { int sum = 0; int count = 0; map Map; Map[0] = 1; for(int i = 0 ; i < nums.size() ; i++) { sum += nums[i]; if(Map.find(sum-k) != Map.end()) { count += Map[sum-k]; } Map[sum]++; } return count; } };
@AyushiSharmaDSA2 жыл бұрын
Yes, we can do m[0]=1 too :)
@amanbhadani88402 жыл бұрын
Very nice explaination as usual,negative numbers in picture makes it little tricky.
@AyushiSharmaDSA2 жыл бұрын
Thank you Aman, glad it was helpful :)
@abhisheke19272 ай бұрын
god this sum wasted around 3hrs and above it many yt videos made the knot complex. but ur video is life saver. thank u.
@AyushiSharmaDSA2 ай бұрын
thank you Abhishek, glad it was helpful 🤗🤗
@nimeshsingh62292 жыл бұрын
good explanation!. i also started doing daily challenges from 2feb
@AyushiSharmaDSA2 жыл бұрын
Thanks Nimesh :)
@prajwalurkude0072 жыл бұрын
Thanks a lot mam ! You making difference, you providing values ✌🏻
@AyushiSharmaDSA2 жыл бұрын
Welcome Prajwal, and thank you so much for appreciating. Means a lot :)
@ambikaarora87362 жыл бұрын
Thanks for explaining sum-k is needed with help of y-k, things got clear at that point .Thanks Ayushi :)
@AyushiSharmaDSA2 жыл бұрын
Welcome Ambika, glad it was helpful :)
@suraj_patwa6 ай бұрын
Example se best samaj me aya Didi Congratulation to join Microsoft
@AyushiSharmaDSA6 ай бұрын
Thanks a lot 😊
@lightyagami-rk2my2 жыл бұрын
I have seen william lin using prefix sum in the google kickstart videos. nice to have it revised here.
@AyushiSharmaDSA2 жыл бұрын
Glad it was helpful :)
@ecs185_shaileshbharti32 жыл бұрын
💯🔥 Reach ++;
@AyushiSharmaDSA2 жыл бұрын
Thank you Shailesh for always supporting :)
@rajdave73572 жыл бұрын
Thank you 🙏🙏
@AyushiSharmaDSA2 жыл бұрын
Welcome :) glad it was helpful
@himanshubarak49442 жыл бұрын
I think instead of the last if else we can simply replace it by just using m[sum]++ in case the element is not present it will be same as setting m[sum]=1. Anyways loved the through explanation as always.
@AyushiSharmaDSA2 жыл бұрын
Yes you are right, we can do that too :) Thanks :)
@lightyagami-rk2my2 жыл бұрын
nice explanation thank you ma'am
@AyushiSharmaDSA2 жыл бұрын
Welcome, glad it was helpful :)
@vaidanshkukreja89702 жыл бұрын
One little doubt 😅 I think Space complexity will be o(1) as u r using an unordered_map and if not then please explain me coz i got little bit confused!
@AyushiSharmaDSA2 жыл бұрын
No, Vaidansh, it will be O(n) , see how. In worst case, what might happen, is that at every index, whatever sum is till that index, we will store in unordered_map, so n elements means n sum i. e n keys in map
@vaidanshkukreja89702 жыл бұрын
@@AyushiSharmaDSA ohh ya i got it now Thanks a lot for the explanation
@SavitarOP2 жыл бұрын
OP Solution
@AyushiSharmaDSA2 жыл бұрын
Thank you Saurabh for always supporting :)
@shadowaj92782 жыл бұрын
🔥🔥, mam is this approach is kadane's algorithm ?
@AyushiSharmaDSA2 жыл бұрын
No, this is not Kadane's algo :)
@shadowaj92782 жыл бұрын
@@AyushiSharmaDSA mam can we apply kadane's in this question!
@vaidanshkukreja89702 жыл бұрын
@@shadowaj9278 Yes i did apply kadane's algo but that didn't work out in some test cases so u have to go through either brute or this one and ya brute will give TLE!!
@shadowaj92782 жыл бұрын
@@vaidanshkukreja8970 ok bro
@amanverma1262 жыл бұрын
Mam could you explain the problem sum of distances in tree from leetcode ?
@AyushiSharmaDSA2 жыл бұрын
Sure Aman, noted :)
@sakshamsengar97982 жыл бұрын
HAPPY TEDDY DAY🧸🧸🧸
@mohdkhaleeq74682 жыл бұрын
Is this random problems you solved from leetcode or daily challenge?
@AyushiSharmaDSA2 жыл бұрын
It's february leetcode daily challenge :)
@rajdave73572 жыл бұрын
@@AyushiSharmaDSA I think at the end you should also metione Day-10 Feb 2022 in the title of video, so that it will help us and also it will be helpful from SEO point of you : )
@AyushiSharmaDSA2 жыл бұрын
@@rajdave7357 okay, thanks for letting me know :)
@karthikruthiravelu83152 жыл бұрын
At kzbin.info/www/bejne/jpuzY6CHp55rjbM , you are saying that we can have anything as value for hashmap which is not true as we have to maintain the count of sum, so the reason why this will not work is that we can have negative values in the sub array and because of which the same sum could have occurred multiple times and we might miss counting the subsequent sub arrays that have summed up to the same value. So it's always necessary to maintain the count of sum in our hashmap.