brilliant explanation of prefix sum, the best of all I've seen on Yourtube. Many thanks man!
@darktez7454 Жыл бұрын
Thanks for the solution... Love from India
@onecodeman Жыл бұрын
Thanks Brother for the Support 🙏
@baaaaaaaaaaaaaaaaaaaaaaam Жыл бұрын
Nice this is probably the best explanation
@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 Жыл бұрын
Amazing solution. Alternatively, you can use the third solution (prefix sum), which is more efficient.
@amrabdelatyfathallah24877 ай бұрын
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 Жыл бұрын
Hi bro and thanks. Sliding Window Technique works also for an array with postive values and zeros ?
@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?