Skip to content

Commit 1b35538

Browse files
authored
Create 1498-number-of-subsequences-that-satisfy-the-given-sum-condition.py
1 parent 2dd132a commit 1b35538

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time Complexity - O(nlogn)
2+
# Space Complexity - O(1)
3+
4+
class Solution:
5+
def numSubseq(self, nums: List[int], target: int) -> int:
6+
nums.sort()
7+
8+
res, mod = 0, (10**9 + 7)
9+
10+
left, right = 0, len(nums) - 1
11+
while left <= right:
12+
if (nums[left] + nums[right]) > target:
13+
right -= 1
14+
else:
15+
res += 1 << (right - left)
16+
left += 1
17+
return res % mod

0 commit comments

Comments
 (0)