Skip to content

Commit

Permalink
Added Solution - GfG to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
101rror committed Jan 5, 2025
1 parent b7a3709 commit 3a945f0
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#{
# Driver Code Starts
#Initial Template for Python 3

import math


# } Driver Code Ends
#User function Template for python3
class Solution:
def countPairs(self, arr, target):
arr.sort()
count = 0
left, right = 0, len(arr) - 1

while left < right:
if arr[left] + arr[right] < target:
count += right - left
left += 1
else:
right -= 1

return count


#{
# Driver Code Starts.

def main():
T = int(input())
while (T > 0):

A = [int(x) for x in input().strip().split()]

k = int(input())
ob = Solution()
print(ob.countPairs(A, k))
print('~')
T -= 1


if __name__ == "__main__":
main()

# } Driver Code Ends

0 comments on commit 3a945f0

Please sign in to comment.