Number of Subsequences That Satisfy the Given Sum Condition
You are given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element in it is less than or equal to target. Since the answer may be too large, return it modulo 10^9 + 7.
30:00
Number of Subsequences That Satisfy the Given Sum Condition
You are given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element in it is less than or equal to target. Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:
Input: {"nums":[3,5,6,7],"target":9}
Output: 4
Constraints:
1≤nums.length≤105
1≤nums[i]≤106
1≤target≤106
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[3,5,6,7],"target":9}
A subsequence qualifies when its smallest plus its largest value is at most 9. Order inside a subsequence does not matter for min and max, so sorting is safe.