Subarray with given Sum | Python Code

preview_player
Показать описание
This video explains how to find a subarray from a given array having sum equals to a given sum value.

This problem is simple to solve but has been very frequently asked in programming interview rounds.

If you find any difficulty or have any query then comment below..

#subarray #sum #python
Рекомендации по теме
Комментарии
Автор

Pls post videos daily you are the best explainer I have ever seen.

sanjaybalaji
Автор

i have a doubt, the dictionary cannot have same keys, so here for index0 the sum is 10 and and we are storing as the key, also the index 3 we have sum 10 that is being stored as key.

yaminikoneti
Автор

i was given a practice exercise at university were i should count in how many ways i can form a subarray that does the given sum. I have to do it in an efficient way and that seems the right way, but i cannot count right. (the array has zeroes and positive integers)

francescojamesfanti
Автор

So the line 10's print statement prints the value in the dictionary right?

sreelekshmiajaykumar
Автор

Tqs for this video.... U were my savior....

shilpagopal
Автор

Can you please make a video on finding kth largest element in an array...I'm getting confusee

pritammishra
Автор

def subarray_sum(arr, sum):
dict1={}
curr_sum=0
for i in range(len(arr)):
curr_sum=curr_sum+arr[i]
if curr_sum == sum:
print("Subarray starts from 0 to ", i)
return
if curr_sum-sum in dict1:
print("subarray starts from ", dict1[curr_sum-sum]+1, "to", i)
return
dict1[curr_sum]=i
print("no subarray found")
arr=[1, 4, 20, 3, 10, 5]
sum=33
subarray_sum(arr, sum)

touheedfathima
Автор

Mam plz make videos on data structures graphs like topological sort nd those similar kind algo's

jeevapriya