Tag Archives: sum in range

Contiguous subarray with sum in a range

Given an array int32 arr[] of size n, return the number of non-empty contigious subarrays whose sum lies in range [a, b] Examples: count([1,2,3], 0, 3) = 4 ( [1], [2], [3], [1, 2]) count([-2,5,-1], -2, 2) = 3 ( [-2], [-1], [-2, 5, -1] ) Naive O(n^2) solution – def naive_algorithm(lst, a, b): result […]