S = 15
arr = [5, 1, 3, 5, 10, 7, 4, 9, 2, 8]
start = 0
current_sum = 0
min_len = len(arr) + 1
for end in range(len(arr)):
current_sum += arr[end]
while current_sum >= S:
length = end - start + 1
if length < min_len:
min_len = length
current_sum -= arr[start]
start += 1
if min_len == len(arr) + 1:
print(0)
else:
print(min_len)
To embed this project on your website, copy the following code and paste it into your website's HTML: