-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrequencyusinghashmap.py
More file actions
40 lines (32 loc) · 839 Bytes
/
frequencyusinghashmap.py
File metadata and controls
40 lines (32 loc) · 839 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
def findCounts(arr, n):
hash = [0 for i in range(n)]
print(hash)
i = 0
while (i < n):
hash[arr[i] - 1] += 1
i += 1
print(hash)
print("Below are counts of all elements")
for i in range(n):
print(i + 1, "->", hash[i], end = " ")
print()
# Driver code
arr = [ 2, 3, 3, 2, 5 ]
findCounts(arr, len(arr))
# arr1 = [1]
# findCounts(arr1, len(arr1))
# arr3 = [ 4, 4, 4, 4 ]
# findCounts(arr3, len(arr3))
# arr2 = [ 1, 3, 5, 7, 9,
# 1, 3, 5, 7, 9, 1 ]
# findCounts(arr2, len(arr2))
# arr4 = [ 3, 3, 3, 3, 3,
# 3, 3, 3, 3, 3, 3 ]
# findCounts(arr4, len(arr4))
# arr5 = [ 1, 2, 3, 4, 5,
# 6, 7, 8, 9, 10, 11 ]
# findCounts(arr5, len(arr5))
# arr6 = [ 11, 10, 9, 8, 7,
# 6, 5, 4, 3, 2, 1 ]
# findCounts(arr6, len(arr6))
# This code is contributed by avanitrachhadiya2155