diff --git a/17EGICS030_HASH_1.py b/17EGICS030_HASH_1.py new file mode 100644 index 0000000..b7beb3f --- /dev/null +++ b/17EGICS030_HASH_1.py @@ -0,0 +1,21 @@ +#Given an integer array arr, count element x such that x + 1 is also in arr. +#If there are duplicates in arr, count them separately. + +#LOGIC +def elements(ele,arr): + count=0 + for e in ele: + count+=arr.count(e) + return count + +#INPUT +size=int(input(("Enter the size of array: "))) +arr=[] + +ele=set() +for i in range(size): + num=int(input()) + arr.append(num) + if num-1 in arr: + ele.add(num-1) +print("Number of elements: ",elements(ele,arr)) \ No newline at end of file diff --git a/17EGICS030_HASH_2.py b/17EGICS030_HASH_2.py new file mode 100644 index 0000000..d10196f --- /dev/null +++ b/17EGICS030_HASH_2.py @@ -0,0 +1,34 @@ +#Given an array of integers, return the number of pairs such that they add up to a specific target. +#You may assume that each input would have exactly one solution, and you may not use the same element twice. + +#LOGIC +def pair(arr,t): + pairs=set() + flag=True + while flag: + for ele in arr: + if ele