-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPicking Number final.py
45 lines (32 loc) · 1.12 KB
/
Picking Number final.py
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
41
42
43
44
45
#Given an array of integers, find and print the maximum number of integers you
#can select from the array such that the absolute difference between any two of
#the chosen integers is less than or equal to . For example, if your array is ,
#you can create two subarrays meeting the criterion: and . The maximum length
#subarray has elements.
list = input().split()
list = [int(i) for i in list]
list.sort()
print(list)
def pickingNumbers(list):
# Write your code here
maximum = []
maxim = 0
while len(list) > 1:
if len(list) != 0:
A = max(list)
count_max = list.count(A)
for j in range(count_max):
list.remove(max(list))
maxim += count_max
if len(list) == 0 and len(maximum) == 0:
return count_max
if len(list) != 0:
B = max(list)
count_max = list.count(B)
maxim += count_max
check = abs(A - B)
if check <= 1:
maximum.append(maxim)
maxim = 0
return max(maximum)
print(pickingNumbers(list))