num = [10, 20, 30, 10, 50, 20, 10]
k = 3

current_sum = sum(num[:k])
max_sum = current_sum

for i in range(k, len(num)):
    current_sum = current_sum - num[i - k] + num[i]
    max_sum = max(max_sum, current_sum)

print(max_sum)

Embed on website

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