-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpickingNumbers.py
More file actions
38 lines (30 loc) · 933 Bytes
/
pickingNumbers.py
File metadata and controls
38 lines (30 loc) · 933 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
def pickingNumbers(a):
# Write your code here
""""
###########Pseudocode############
sort a
counter
sort list set(a)
-> for val in list:
-> if next value:
-> if next val - val <= 1:
-> count val and next val in a
-> append to counter
return max(counter)
"""
a.sort()
counter = []
unique = sorted(list(set(a)))
if len(unique) == 1:
return len(a)
for i in range(len(unique)):
try:
if unique[i+1]:
if unique[i+1] - unique[i] <= 1:
count = a.count(unique[i]) + a.count(unique[i+1])
counter.append(count)
count = a.count(unique[i])
counter.append(count)
except:
break
return max(counter)