def solution(daily_sales, periods):
    prefix = [0]

    for sale in daily_sales:
        prefix.append(prefix[-1] + sale)

    answer = []

    for start, end in periods:
        answer.append(prefix[end + 1] - prefix[start])

    return answer


daily_sales = [3, 5, 2, 7, 1]
periods = [[0, 2], [1, 3], [2, 4]]

print(solution(daily_sales, periods))

Embed on website

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