-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathequalize-the-array.py
More file actions
31 lines (23 loc) · 915 Bytes
/
equalize-the-array.py
File metadata and controls
31 lines (23 loc) · 915 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
# Solution for the problem "Equalize the Array"
# https://www.hackerrank.com/challenges/equality-in-a-array/problem
# Number of values
numValues = int(input().strip())
# Reading n values into the list
valuesList = list(map(int, input().strip().split(' ')))
# Dictionary to hold count of each value
countValues = {}
# Iterate over the values to get the count on distinct items
for val in valuesList:
# Read count from dictionary
currentCount = countValues.get(val)
# In case value doesnt exist, set it to one
if currentCount == None:
currentCount = 1
# Otherwise increment the value
else:
currentCount = currentCount + 1
# Put value into dictionary
countValues[val] = currentCount
# To find minimum number of deletions, we need to find maximum count and delete from total count of values
numDeletions = numValues - max(countValues.values())
print(numDeletions)