Count Subsequences by Minimum and Maximum
Count the subsequences whose smallest plus largest value is at most target.
The problem
Implement Solution.numSubseq(nums, target). Count the non-empty subsequences of nums whose minimum value plus maximum value is at most target. Subsequences are picked by position, so equal values at different positions give different subsequences. Return the count modulo 1,000,000,007. For example, with nums = [3, 5, 6, 7] and target = 9 the answer is 4: [3], [3, 5], [3, 5, 6] and [3, 6]. nums has between 1 and 100,000 values, each from 1 to 1,000,000, and 1 <= target <= 1,000,000.
Starter code
class Solution:
def numSubseq(self, nums, target):
passPublic examples
nums = [3, 5, 6, 7], target = 9gives4nums = [5], target = 9gives0nums = [2, 2, 2], target = 4gives7
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
