We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 62efcb4 commit 965e027Copy full SHA for 965e027
twoSumusingHashMap.py
@@ -0,0 +1,19 @@
1
+
2
+'''The below approach is using Hash data structure where we store only the unique values of the array
3
+This approach can be extended to 3sum problem as well
4
+'''
5
+def printPairs(arr, arr_size, sum):
6
+ hashmap = {}
7
8
+ for i in range(0, arr_size):
9
+ temp = sum-arr[i]
10
+ if (temp in hashmap):
11
+ print('Yes')
12
+ return
13
+ hashmap[arr[i]] = i
14
+ print("No")
15
16
17
+A = [1, 4, 45, 6, 10, 8]
18
+n = 16
19
+printPairs(A, len(A), n)
0 commit comments