-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPairs.py
More file actions
42 lines (29 loc) · 681 Bytes
/
Pairs.py
File metadata and controls
42 lines (29 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'''
Problem Statement: https://www.hackerrank.com/challenges/pairs/problem
@Coded by TSG, 2020
'''
import math
import os
import random
import re
import sys
# Complete the pairs function below.
def pairs(k, arr):
res = 0
memo = dict()
for el in arr:
if el-k in memo:
res += 1
if el+k in memo:
res += 1
memo[el] = True
return res
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nk = input().split()
n = int(nk[0])
k = int(nk[1])
arr = list(map(int, input().rstrip().split()))
result = pairs(k, arr)
fptr.write(str(result) + '\n')
fptr.close()