-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcut_the_sticks.py
More file actions
37 lines (21 loc) · 932 Bytes
/
cut_the_sticks.py
File metadata and controls
37 lines (21 loc) · 932 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
# Solution of the challenge Cut the Sticks proposed on HackerRank at https://www.hackerrank.com/challenges/cut-the-sticks/problem
import math
import random
import re
import sys
# A list called occ contains the occurrences of all non-dubplicate elements from arr sorted into ascending order.
# A list called recurr should start with len(arr) and go ahead with the difference between len(arr) and the first
# element of occ. Iterating this process until the difference recurr[i]-occ[i] = 0 will solve the problem.
def cutTheSticks(arr):
occ = [arr.count(item) for item in sorted(list(set(arr)))]
recurr = [len(arr)]
for i in range(len(occ)):
m = recurr[i]-occ[i]
if m != 0:
recurr.append(m)
return recurr
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().rstrip().split()))
result = cutTheSticks(arr)
print('\n'.join(map(str, result)))