forked from Srinivas11789/AlgorithmNuggets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpairs.py
More file actions
35 lines (31 loc) · 788 Bytes
/
pairs.py
File metadata and controls
35 lines (31 loc) · 788 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
#!/bin/python
import sys
def pairs(k, arr):
# Complete this function
counts = 0
for i in range(len(arr)):
value = k - arr[i]
if value in arr[i+1:]:
counts += 1
return counts
"""
# Timeout
counts = {}
pairs = 0
for item in arr:
if item not in counts:
counts[item] = 0
counts[item] = abs(k-item)
#print(counts)
for key, value in counts.items():
if key in arr and value in arr and abs(key-value) == k:
#print(key,value)
pairs += 1
return pairs
"""
if __name__ == "__main__":
n, k = raw_input().strip().split(' ')
n, k = [int(n), int(k)]
arr = map(int, raw_input().strip().split(' '))
result = pairs(k, arr)
print result