25. Subarray Sum Equals K | Leetcode 560 | Array | Prefix Sum

  Рет қаралды 21,036

Ayushi Sharma

Ayushi Sharma

Күн бұрын

Пікірлер: 60
@intezaralam9357
@intezaralam9357 2 жыл бұрын
At 1:45 , we have one more subarray of sum 9, i.e 1, 3, 2, 3
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Yes, that I missed, in later part of video, we did found out. Pinning your comment so that others can know. Thanks :)
@devendratumu1704
@devendratumu1704 2 жыл бұрын
the way you are explaining the problem is very good keep doing more
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Devendra :)
@rajdave7357
@rajdave7357 2 жыл бұрын
Yes, She is awesome
@vaibhavgoel7750
@vaibhavgoel7750 2 жыл бұрын
Yes, she is excellent in explanation.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
@@vaibhavgoel7750 @Raj dave thanks guys🥺😄
@rishalirishu5833
@rishalirishu5833 2 жыл бұрын
Oh god...I tried soln from so many channels but unable to understand....Finally you are back wth the solution
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Rishali, glad it was helpful :)
@rohangangwar6604
@rohangangwar6604 2 жыл бұрын
after doing some questions i observed one thing that most of the questions on subarrays can be solved using maps with optimisation.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Yes :)
@RajeshS-n2j
@RajeshS-n2j 3 ай бұрын
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. 😀
@AyushiSharmaDSA
@AyushiSharmaDSA 3 ай бұрын
Glad it was helpful! thank you :)
@CodeWithSeenu
@CodeWithSeenu 3 ай бұрын
Thanks a million.. this explanation solved lots of doubts
@AyushiSharmaDSA
@AyushiSharmaDSA 3 ай бұрын
welcome, glad it helped :)
@alienx2367
@alienx2367 2 жыл бұрын
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; } };
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Yes, we can do m[0]=1 too :)
@amanbhadani8840
@amanbhadani8840 2 жыл бұрын
Very nice explaination as usual,negative numbers in picture makes it little tricky.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Aman, glad it was helpful :)
@abhisheke1927
@abhisheke1927 2 ай бұрын
god this sum wasted around 3hrs and above it many yt videos made the knot complex. but ur video is life saver. thank u.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 ай бұрын
thank you Abhishek, glad it was helpful 🤗🤗
@nimeshsingh6229
@nimeshsingh6229 2 жыл бұрын
good explanation!. i also started doing daily challenges from 2feb
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thanks Nimesh :)
@prajwalurkude007
@prajwalurkude007 2 жыл бұрын
Thanks a lot mam ! You making difference, you providing values ✌🏻
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Welcome Prajwal, and thank you so much for appreciating. Means a lot :)
@ambikaarora8736
@ambikaarora8736 2 жыл бұрын
Thanks for explaining sum-k is needed with help of y-k, things got clear at that point .Thanks Ayushi :)
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Welcome Ambika, glad it was helpful :)
@suraj_patwa
@suraj_patwa 6 ай бұрын
Example se best samaj me aya Didi Congratulation to join Microsoft
@AyushiSharmaDSA
@AyushiSharmaDSA 6 ай бұрын
Thanks a lot 😊
@lightyagami-rk2my
@lightyagami-rk2my 2 жыл бұрын
I have seen william lin using prefix sum in the google kickstart videos. nice to have it revised here.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Glad it was helpful :)
@ecs185_shaileshbharti3
@ecs185_shaileshbharti3 2 жыл бұрын
💯🔥 Reach ++;
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Shailesh for always supporting :)
@rajdave7357
@rajdave7357 2 жыл бұрын
Thank you 🙏🙏
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Welcome :) glad it was helpful
@himanshubarak4944
@himanshubarak4944 2 жыл бұрын
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.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Yes you are right, we can do that too :) Thanks :)
@lightyagami-rk2my
@lightyagami-rk2my 2 жыл бұрын
nice explanation thank you ma'am
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Welcome, glad it was helpful :)
@vaidanshkukreja8970
@vaidanshkukreja8970 2 жыл бұрын
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!
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
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
@vaidanshkukreja8970
@vaidanshkukreja8970 2 жыл бұрын
@@AyushiSharmaDSA ohh ya i got it now Thanks a lot for the explanation
@SavitarOP
@SavitarOP 2 жыл бұрын
OP Solution
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Saurabh for always supporting :)
@shadowaj9278
@shadowaj9278 2 жыл бұрын
🔥🔥, mam is this approach is kadane's algorithm ?
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
No, this is not Kadane's algo :)
@shadowaj9278
@shadowaj9278 2 жыл бұрын
@@AyushiSharmaDSA mam can we apply kadane's in this question!
@vaidanshkukreja8970
@vaidanshkukreja8970 2 жыл бұрын
@@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!!
@shadowaj9278
@shadowaj9278 2 жыл бұрын
@@vaidanshkukreja8970 ok bro
@amanverma126
@amanverma126 2 жыл бұрын
Mam could you explain the problem sum of distances in tree from leetcode ?
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Sure Aman, noted :)
@sakshamsengar9798
@sakshamsengar9798 2 жыл бұрын
HAPPY TEDDY DAY🧸🧸🧸
@mohdkhaleeq7468
@mohdkhaleeq7468 2 жыл бұрын
Is this random problems you solved from leetcode or daily challenge?
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
It's february leetcode daily challenge :)
@rajdave7357
@rajdave7357 2 жыл бұрын
@@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 : )
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
@@rajdave7357 okay, thanks for letting me know :)
@karthikruthiravelu8315
@karthikruthiravelu8315 2 жыл бұрын
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.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Yes, you are right, said there by mistake :)
Count Subarray sum Equals K | Brute - Better -Optimal
24:09
take U forward
Рет қаралды 365 М.
Subarray Sum Equals K - Prefix Sums - Leetcode 560 - Python
15:19
Thank you mommy 😊💝 #shorts
0:24
5-Minute Crafts HOUSE
Рет қаралды 33 МЛН
БАБУШКА ШАРИТ #shorts
0:16
Паша Осадчий
Рет қаралды 4,1 МЛН
번쩍번쩍 거리는 입
0:32
승비니 Seungbini
Рет қаралды 182 МЛН
Prefix Sum Array and Range Sum Queries
7:30
Profound Academy
Рет қаралды 7 М.
Permutation in String | Leetcode 567 | Sliding window | Day 11
22:05
Subarray Sum Equals K - LeetCode 560 - Coding Interview Questions
10:38
Prefix Sums - Problems, Code in C++ & Python
20:51
Errichto Algorithms
Рет қаралды 59 М.
Contiguous Array | Leetcode 525 | Arrays
27:27
Ayushi Sharma
Рет қаралды 6 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 234 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 707 М.
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 466 М.
Thank you mommy 😊💝 #shorts
0:24
5-Minute Crafts HOUSE
Рет қаралды 33 МЛН