-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKey pair.py
77 lines (63 loc) · 1.69 KB
/
Key pair.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# User function Template for python3
class Solution:
def hasArrayTwoCandidates(self, arr, n, x):
dic = {}
for i in arr:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
for i in arr:
if x - i in dic:
if x - i == i:
if dic[i] - 1 > 0:
return True
else:
continue
return True
return False
# {
# Driver Code Starts
# Initial Template for Python 3
if __name__ == "__main__":
tc = int(input())
while tc > 0:
n, x = list(map(int, input().strip().split()))
arr = list(map(int, input().strip().split()))
ob = Solution()
ans = ob.hasArrayTwoCandidates(arr, n, x)
if ans:
print("Yes")
else:
print("No")
tc -= 1
class Solution:
def hasArrayTwoCandidates(self, arr, n, x):
dic = {}
for i in arr:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
for i in arr:
if x - i in dic:
if x - i == i:
if dic[i] - 1 > 0:
return True
else:
continue
return True
return False
if __name__ == "__main__":
tc = int(input())
while tc > 0:
n, x = list(map(int, input().strip().split()))
arr = list(map(int, input().strip().split()))
ob = Solution()
ans = ob.hasArrayTwoCandidates(arr, n, x)
if ans:
print("Yes")
else:
print("No")
tc -= 1
# } Driver Code Ends