Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created July 28, 2025 14:58
Show Gist options
  • Select an option

  • Save inspirit941/f3535b21a5705c318c80b14bacc6ed5d to your computer and use it in GitHub Desktop.

Select an option

Save inspirit941/f3535b21a5705c318c80b14bacc6ed5d to your computer and use it in GitHub Desktop.
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'pairs' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER k
# 2. INTEGER_ARRAY arr
#
def pairs(k, arr):
# Write your code here
candidates = set(arr)
answer = 0
for data in arr:
if data + k in candidates:
answer += 1
return answer
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
k = int(first_multiple_input[1])
arr = list(map(int, input().rstrip().split()))
result = pairs(k, arr)
fptr.write(str(result) + '\n')
fptr.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment