subarray sum equals k leetcode | subarray sum equal to k python | amazon interview question
Vložit
- čas přidán 21. 04. 2020
- ✅ Best book for coding interview - amzn.to/3F3FW8q
✅ Please subscribe to our second channel - / @thecodingworldpodcast659
Please like the video, this really motivates us to make more such videos and helps us to grow. thecodingworld is a community which is formed to help fellow student and professionals looking to crack the “coding interviews”.
We love solving and sharing problems which are frequently asked in technical interviews and voted by community at various websites.
Our website: thecodingworld.com/
✅ For more and upcoming updates join our community
DISCORD - / discord
TELEGRAM - t.me/joinchat/AAAAAEi9eHNAeJI...
INSTAGRAM - thecodingworld?...
FACEBOOK - / 50214. .
Email - info.thecodingworld@gmail.com
✅ Struggling solving leetcode question give yourself a 5 min break ➡️➡️ • Video
#leetcode #python
You did a better job at explaining than NeetCode did for this question. Well done.
rather than explaining what you did , u must explain " why u did that". because we don't get the intuition or the idea behind it.
yep
I agree, the video creator jumps into the solution directly. Any tom, dick and harry can do so. Waste of time.]
I think the video creator explain himself very clearly based on the question that was asked. What you should be asking is why was this question asked in the first place. This video was very helpful in understanding the concept involved in solving the question (IMO).
@@nwokolobueze7291 Did you even watch the video? He said "So what will be an optimized approach" and then straight went to "Let's take cumulative sum" and then straight to subtracting them. Bruh why should we use cumulative sum specifically and not any other approach, what is the intuition behind it we need to know that right. He didnt explain that and applied directly because he saw it somewhere else and memorized it. And we learned the same, to memorize it. There's no point in memorizing a specific approach to a specific question
seen so many other videos on the same problem, but the explanation that u give is exemplary, loved the explanation
Thank you ! I like the way you take the time, to first, explain the approach, before you begin coding.
Glad it was helpful!
best explanation of this problem I've come across with. Thank you! A lot of the other videos doesn't explain count += map.get(sum-k) part very well. But this is gold!
By far the best approach and well explained
You are awesome. Struggled hella. Finally understood this algo.
Awesome, thank you!
dude ur so smart... and ur explanation is so clear its like ASMR
Thanks for the explanation! I was having a hard time understanding it for a while but it's clear now!
Me too, That was why I came here in the first place. I was not understanding the question at first.
Thank you! Very easy to understand the explanation!
Perfect explanation! Great Job
thank you, that's a really nice solution! How can one build such intuition to apply math operations and think outside the box, rather than getting stuck at the layman approach of n*n time complexity?
Thank you so much , was breaking my head with neetcode
multidimensionality approach in your videos for answers is really good..
you should increase value of the key only when the key shows up again in prefix sum array, but you are also increasing the value when the key shows up as diff here
clean and clear explanation !!
in line 15, why we are adding comulative sum to the dictonary by intial value 1 ? it could be any next indexed value
Keep the good work
a) Why was the count for 14 was increased to 3
b) Also, try this input
[4,-2,2,1] with sum = 1 the output would be 2 whereas the actual output is only 1 i.e [-2,2,1]
i agree with you on "a", seems wrong. but for "b" {1} itself is also a subarray.
You're perfect.Just subscibed🤞
Yay! Thank you!
@@thecodingworldpythonwat is the time complexity?
Thank u bhaiya,for giving explaining it easy way,keep doing it
Nice explanation.Example array is good one.
This is really good work.
When I changed the sequence of if statements, it gave me an error. Why? Aren't they parallel?
Thanks for providing a solution to this problem. I have liked and subscribed. I hope that motivates you guys to do more.
Also, maybe someone else have asked this questions before, but why did you initialize n = len(nums) ? Because you did not use it in the code.
I just shared this video on leetcode discussion board, hopefully more users head over here to learn more
Please do more videos very good explanation !
sirji damn cool video respect++
we don't really need to put {0:1} in hashmap initially, wen cumulative sum become 7, it would take care of {0:1}.
great explanation though!!
Hi very nice explanation. Also which software do you use for drawing on screen.
If I have to return the subarray which contains elements, what would be the logic?
nicely done
ThankYou Parrot !!
OSM
Ohhhhh freakkkk that was tricky damn!!! For those who are wondering about why do he incremented count when 13 occurs bcz 20-7 = 13 means if difference of curr sum - 7 == 13 that array between that is 7 and depending on how many time 13 sum is encountered we increment var count by that number
Please tell more about that
I don't know
Look I use ohhh and freekkkk i am cool
IN the last 3 elements in your example giving the sum of 7 then why we wrent counting that
Will you please explain why you get count equals 6? Your input to yield count = 4 not 6
but the count method explained has also time complexity O(n*n)
correct if i m wrong.
What is the meaning of count = count+ sumdict [s-k]
Sliding window pattern can work?? Please tell me
Even I was thinking..
And how the sum is added in dictionary
Thanks for your clear explanation. However, your explanation is not valid for an array with elements [1, 2, 1, 3] and k = 3. This array has running (cumulative) sums of [1, 3, 4, 7] and based on your explanation only one contiguous subarrays exists: [1, 2], while it should be three: [1, 2], [2, 1], and [3] . According to your explanation, differences between each element in [1, 3, 4, 7] and k = 3 is [-2, 0, 1, 4], which are all new values in the hash table. Therefore, the hash table becomes {0:1, 1:1, 3:1, 4:1, 7:1}. Can you please tell me where I am wrong?
#IS MY APPROACH IS OK ?
a = [int(x) for x in input().split()]
k = int(input())
ans = [1 for i in range(len(a)) for j in range(i+1,len(a)+1) if sum(a[i:j])==k]
print(len(ans))
Has anyone tried this code its not working for me.
4:35 confused with 7-7 why this it should be 7-14 correct ?
Its sum - k value.. thats why it is 7 - 7..