Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Count of Range Sum

XPChallenge Points: 30
levelLevel: Hard

Given an array of integers nums and two integers lower and upper, determine how many subarrays have a sum that falls within the inclusive range [lower, upper].

A subarray sum is computed as the total of elements from index i to j (where i ≤ j).
Your task is to count how many such subarrays produce a sum between the given bounds.

Example 1:

Input: nums = [4, -1, -2, 7], lower = 0, upper = 5

Output: 5

Explanation:

Valid ranges are [4], [4,-1,-2], [-1,-2,7].

Example 2:

Input: nums = [2], lower = 1, upper = 3

Output: 1

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result