box = [2, 5, 1, 3, 4, 7, 9]
K = 15

left = 0
current_sum = 0
count = 0

for right in range(len(box)):
    current_sum += box[right]

    while current_sum > K:
        current_sum -= box[left]
        left += 1

    if current_sum == K:
        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: