java.lang.Object
g1401_1500.s1498_number_of_subsequences_that_satisfy_the_given_sum_condition.Solution

public class Solution extends Object
1498 - Number of Subsequences That Satisfy the Given Sum Condition.<p>Medium</p> <p>You are given an array of integers <code>nums</code> and an integer <code>target</code>.</p> <p>Return <em>the number of <strong>non-empty</strong> subsequences of</em> <code>nums</code> <em>such that the sum of the minimum and maximum element on it is less or equal to</em> <code>target</code>. Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [3,5,6,7], target = 9</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> There are 4 subsequences that satisfy the condition.</p> <p>[3] -> Min value + max value <= target (3 + 3 <= 9)</p> <p>[3,5] -> (3 + 5 <= 9)</p> <p>[3,5,6] -> (3 + 6 <= 9)</p> <p>[3,6] -> (3 + 6 <= 9)</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [3,3,6,8], target = 10</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> There are 6 subsequences that satisfy the condition. (nums can have repeated numbers). [3] , [3] , [3,3], [3,6] , [3,6] , [3,3,6]</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [2,3,3,4,6,7], target = 12</p> <p><strong>Output:</strong> 61</p> <p><strong>Explanation:</strong> There are 63 non-empty subsequences, two of them do not satisfy the condition ([6,7], [7]). Number of valid subsequences (63 - 2 = 61).</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>6</sup></code></li> <li><code>1 <= target <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numSubseq

      public int numSubseq(int[] nums, int target)