Skip to content

Practice Count of Sub-Multisets With Bounded Sum

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2902
LeetCode Problem

Count of Sub-Multisets With Bounded Sum

Problem Statement

Count unordered sub-multisets of nums whose sum is between l and r inclusive. Each value may be selected from zero times up to its occurrence count in nums. Selections with the same value multiplicities count once regardless of which equal-valued indices supplied them. The empty selection has sum 0. Return the count modulo 10^9 + 7.

Source: Count of Sub-Multisets With Bounded Sum on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,2,2,3], l = 6, r = 6
Output
1

# Example 2

Input
nums = [2,1,4,2,7], l = 1, r = 5
Output
7

# Example 3

Input
nums = [1,2,1,3,5,2], l = 3, r = 5
Output
9

Constraints

1 <= nums.length <= 2 * 10^4
0 <= nums[i] <= 2 * 10^4
Sum of nums does not exceed 2 * 10^4.
0 <= l <= r <= 2 * 10^4

Related LeetCode Problems

Practice more problems similar to Count of Sub-Multisets With Bounded Sum.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.