arr = [1,2,3,2,5]

M = 5

n = len(arr)
start = 0
sum = 0
count = 0

for end in range(n):
    sum += arr[end]

    while sum > M:
        sum -= arr[start]
        start += 1

    if sum == M:
        count += 1

print(count)
    

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: