Skip to content

Commit

Permalink
Added solution for Count Pairs Whose Sum is Less than Target
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacknahil committed Jan 3, 2024
1 parent e45a7d2 commit a4e17c4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions week5/count-pairs-whose-sum-is-less-than-target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution:
def countPairs(self, nums: List[int], target: int) -> int:
slow,fast=0,len(nums)-1
nums.sort()
count=0
while fast>slow :
if nums[slow] + nums[fast]< target:
count+=fast-slow
slow+=1
else:
fast-=1
return count



0 comments on commit a4e17c4

Please sign in to comment.