A billing period lists n invoices in order, each a positive integer amount. Count how many contiguous runs of invoices have a total amount within the inclusive range [L, R].
Line 1: three integers n, L, and R.
Line 2: n space-separated positive integers, the invoice amounts in order.
A single integer: the number of contiguous subarrays whose sum is at least L and at most R.
Example 1
Input
5 3 6 1 2 3 1 4
Expected
8
Explanation
Runs whose total is between 3 and 6 inclusive number 8: for example [1,2], [1,2,3], [2,3], [2,3,1], [3], [3,1], [1,4], [4].
Example 2
Input
3 10 10 2 3 5
Expected
1
Explanation
Only the whole run [2,3,5] totals exactly 10, so exactly one run falls in [10,10].
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →