-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPicking Numbers.py
51 lines (38 loc) · 972 Bytes
/
Picking Numbers.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
46
47
48
49
50
51
'''
Problem Statement: https://www.hackerrank.com/challenges/picking-numbers/problem
@Coded by TSG, 2020
'''
import math
import os
import random
import re
import sys
#
# Complete the 'pickingNumbers' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY a as parameter.
#
def pickingNumbers(arr):
arr_s = sorted(arr)
res = 1
cur = 1
diff = 0
for ind in range(1, len(arr_s)):
diff += arr_s[ind] - arr_s[ind - 1]
if diff > 1:
res = max(res, cur)
cur = 1
diff = 0
else:
cur += 1
res = max(res, cur)
return res
# Write your code here
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
a = list(map(int, input().rstrip().split()))
result = pickingNumbers(a)
fptr.write(str(result) + '\n')
fptr.close()