파이썬 코딩테스트/해커랭크

HackerRank / Picking Numbers / Python

S.T.Lee 2022. 1. 7. 23:04

https://www.hackerrank.com/challenges/picking-numbers/problem?isFullScreen=true

 

Picking Numbers | HackerRank

What's the largest size subset can you choose from an array such that the difference between any two integers is not bigger than 1?

www.hackerrank.com

문제 해석을 잘 해야된다.

주어진 리스트 안에서 한개의 인자를 고를 수 있다.

해당 인자와 해당 인자들 다른 인자들과 비교했을때 같거나 1만큼 작은 인자들로 리스트를 만들때

가장 긴 리스트의 길이를 돌려준다.

 

def pickingNumbers(a):
    # Write your code here
    max_count = 0
    for aa in a:
        self_count = a.count(aa)
        else_count = a.count(aa-1)
        sum_two = self_count + else_count
        if max_count < sum_two:
            max_count = sum_two
    return max_count