Subarray Sum Equals K - LeetCode 560 - Coding Interview Questions

  Рет қаралды 2,736

One Code Man

One Code Man

Күн бұрын

Link to the Problem : leetcode.com/problems/subarra...
Buy Me a Coffee ☺️ : www.buymeacoffee.com/Onecodeman
---- ------
The problem is that they give us an array of integers, and they ask us to return the total number of subarrays whose sum equals to K.
To Solve this Problem we gonna use two techniques Sliding Window and prefix-sum.
Next, we present the solution and walk you through the code step by step, highlighting the key points and explaining the logic behind each part of the solution.
Whether you are preparing for a technical interview or just looking to improve your coding skills, this video is a great resource.
If you found this video helpful, like, subscribe, comment.
#codinginterviewquestions #leetcodedailychallenge #leetcodesolution #leetcodedailychallenge #leetcodequestionandanswers
---- ----
Understanding the problem : (0:00)
How do you ask questions in coding interview? : (0:38)
Sliding Window Technique : (1:19)
Complexity Analysis : (4:04)
Code Explanation : (4:16)
Prefix-sum Technique : (5:46)
Complexity Analysis : (9:32)
Code Explanation : (9:45)

Пікірлер: 12
@baaaaaaaaaaaaaaaaaaaaaaam
@baaaaaaaaaaaaaaaaaaaaaaam Жыл бұрын
Nice this is probably the best explanation
@darktez7454
@darktez7454 Жыл бұрын
Thanks for the solution... Love from India
@onecodeman
@onecodeman Жыл бұрын
Thanks Brother for the Support 🙏
@amrabdelatyfathallah2487
@amrabdelatyfathallah2487 3 ай бұрын
can i ask question in sliding window in excatly this part : # Expand sliding window if total < k: end += 1 if end == len(nums): break total += nums[end] this snippet of code should be like this: # Expand sliding window if total < k: if end == len(nums): break end += 1 total += nums[end] because imagine if we have start pointer anywhere in array and end on element previous last one and total < k: so we need to expand so we increase end pointer by one and if we check first the condition of end == len(nums) will be true and it will break loop and return counter for example = 1 but if we check first when end on element previous last one the condition will be false and we increase end pointer by one and total will change and it will loop again and check if total > k or total == k or total < k lets say it will be total becomes equal to k it will increase counter by one and shrink window and it will break the loop after this and correct for me if iam wrong
@novascotia2015
@novascotia2015 Жыл бұрын
If the input array can contain negative numbers, we need to modify the sliding window approach to handle negative sums. One way to handle negative numbers is to use a hash table to store the number of occurrences of each prefix sum encountered so far. At each iteration, we can check if the difference between the current prefix sum and the target sum k is already in the hash table. If it is, we add the number of occurrences of that prefix sum to the answer.
@onecodeman
@onecodeman Жыл бұрын
Amazing solution. Alternatively, you can use the third solution (prefix sum), which is more efficient.
@francescomangano1996
@francescomangano1996 Жыл бұрын
Hi bro and thanks. Sliding Window Technique works also for an array with postive values and zeros ?
@msakshayakumar
@msakshayakumar 8 ай бұрын
doesn't seem like it because we move the start index once total == sum. maybe if we change the logic to: if total greater than K, then move the start index, we could make it work?
@novascotia2015
@novascotia2015 Жыл бұрын
love you
@onecodeman
@onecodeman Жыл бұрын
🙏
@madhu601
@madhu601 2 күн бұрын
Please pause while you explain
3Sum Closest - LeetCode 16 - Coding Interview Questions
6:26
One Code Man
Рет қаралды 2,1 М.
Subarray Sum Equals K - Prefix Sums - Leetcode 560 - Python
15:19
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 49 МЛН
No empty
00:35
Mamasoboliha
Рет қаралды 10 МЛН
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 91 МЛН
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 8 МЛН
Count Subarray sum Equals K | Brute - Better -Optimal
24:09
take U forward
Рет қаралды 255 М.
SUBARRAY SUM EQUALS K | LEETCODE 560 | PYTHON SOLUTION
16:32
Cracking FAANG
Рет қаралды 2,5 М.
Mock Technical Interview - Javascript Developer Entry Level
1:36:22
Tech with Nader
Рет қаралды 495 М.
Разбор задачи 560 leetcode.com Subarray Sum Equals K. Решение на C++
38:56
3.5 задачи в неделю
Рет қаралды 1,1 М.
Continuous Subarray Sum - Leetcode 523 - Python
14:56
NeetCode
Рет қаралды 64 М.
Coding Interview Problem - Subarray Sum Equals K
9:22
Knapsack
Рет қаралды 7 М.
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 49 МЛН