Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution in Python
1# Runtime: 637 ms (Top 91.1%) | Memory: 29.39 MB (Top 30.6%)234class Solution:5def numSubseq(self, nums: List[int], target: int) -> int:6nums.sort()7left, right = 0, len(nums) - 18count = 09mod = 10**9 + 71011while left <= right:12if nums[left] + nums[right] > target:13right -= 114else:15count += pow(2, right - left, mod)16left += 11718return count % mod