본문 바로가기
HackerRank Algorithm

[HackerRank] 27. Picking Numbers

by KIha_Jung 2020. 4. 7.

def pickingNumbers(a):
    high = 1
    low = 1
    maximum = 0
    for n in a:
        high = a.count(n+1) + a.count(n)
        low = a.count(n-1) + a.count(n)
        maximum = max(maximum, high, low)

    return maximum
            

if __name__ == '__main__':
    n = int(input().strip())
    a = list(map(int, input().rstrip().split()))
    
    result = pickingNumbers(a)
    print(result)

'HackerRank Algorithm' 카테고리의 다른 글

[HackerRank] 26. forming a magic square  (0) 2020.04.07
[HackerRank] 25. Cats and Mouse  (0) 2020.04.07
[HackerRank] 24. Electronics shop  (0) 2020.04.07
[HackerRank] 23. Apple and orange  (0) 2020.04.07
[HackerRank] 22. Between Two Sets  (0) 2020.04.07

댓글