Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //first approach is brute force
- class Solution:
- #Complete the below function
- def countPairs(self, arr, target):
- arr=sorted(arr)
- ans=0
- i=0
- j=len(arr)-1
- while i<j:
- if arr[i]+arr[j]>=target:
- j-=1
- else:
- ans+= (j-i)
- i+=1
- return ans
- // If current left and current right have sum smaller than x,
- // the all elements from l+1 to r form a pair with current l.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement