Subarray Sum Equals K - LeetCode 560 - Coding Interview Questions

  Рет қаралды 4,329

One Code Man

One Code Man

Күн бұрын

Пікірлер: 13
@USRetro
@USRetro Ай бұрын
brilliant explanation of prefix sum, the best of all I've seen on Yourtube. Many thanks man!
@darktez7454
@darktez7454 Жыл бұрын
Thanks for the solution... Love from India
@onecodeman
@onecodeman Жыл бұрын
Thanks Brother for the Support 🙏
@baaaaaaaaaaaaaaaaaaaaaaam
@baaaaaaaaaaaaaaaaaaaaaaam Жыл бұрын
Nice this is probably the best explanation
@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.
@amrabdelatyfathallah2487
@amrabdelatyfathallah2487 7 ай бұрын
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
@francescomangano1996
@francescomangano1996 Жыл бұрын
Hi bro and thanks. Sliding Window Technique works also for an array with postive values and zeros ?
@msakshayakumar
@msakshayakumar Жыл бұрын
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?
@madhu601
@madhu601 3 ай бұрын
Please pause while you explain
@novascotia2015
@novascotia2015 Жыл бұрын
love you
@onecodeman
@onecodeman Жыл бұрын
🙏
3Sum Closest - LeetCode 16 - Coding Interview Questions
6:26
One Code Man
Рет қаралды 2,5 М.
Subarray Sum Equals K - Prefix Sums - Leetcode 560 - Python
15:19
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 119 МЛН
This Game Is Wild...
00:19
MrBeast
Рет қаралды 186 МЛН
How to Fight a Gross Man 😡
00:19
Alan Chikin Chow
Рет қаралды 17 МЛН
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 7 МЛН
SUBARRAY SUM EQUALS K | LEETCODE 560 | PYTHON SOLUTION
16:32
Cracking FAANG
Рет қаралды 4,5 М.
Count Subarray sum Equals K | Brute - Better -Optimal
24:09
take U forward
Рет қаралды 337 М.
Coding Interview Problem - Subarray Sum Equals K
9:22
Knapsack
Рет қаралды 8 М.
Google Coding Interview With A Competitive Programmer
54:17
Clément Mihailescu
Рет қаралды 2,5 МЛН
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 586 М.
25. Subarray Sum Equals K | Leetcode 560 | Array | Prefix Sum
17:27
Ayushi Sharma
Рет қаралды 20 М.
LeetCode Subarray Sum Equals K Solution Explained - Java
10:08
Nick White
Рет қаралды 96 М.
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 119 МЛН