Bounded Range Sum Count Problem

Bounded Range Sum Count Problem — ExecCode Hard DSA Practice

Solve the Bounded Range Sum Count problem on ExecCode. Free online hard DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Count how many contiguous subarrays have a sum lying in [lower, upper]. Prefix sums turn this into 'how many previous prefixes lie in [S-upper, S-lower]'. Hard OAs expect merge-sort on prefixes, not O(n²). Return the number of subarrays whose sum is between lower and upper inclusive. You are given: nums — integer array lower — inclusive lower bound upper — inclusive upper bound, lower <= upper Return integer count. A single element is a subarray.

Examples

Input {'nums': [-2, 5, -1], 'lower': -2, 'upper': 2}; Output 3. Input {'nums': [0], 'lower': 0, 'upper': 0}; Output 1. Input {'nums': [1, 2, 3], 'lower': 3, 'upper': 3}; Output 2

Constraints

Subarrays are contiguous and non-empty Prefix sums may be negative

Practice Bounded Range Sum Count free on ExecCode. Browse DSA problems, topic map, and placement guides.