Picking Numbers

  • + 1 comment

    Python

    def pickingNumbers(a):
        cnt = [0] * (max(a) + 1)
        for num in a:
            cnt[num] += 1
    
        res = 0
        for i in range(len(cnt) - 1):
            curr_sum = cnt[i] + cnt[i + 1]
            if curr_sum > res:
                res = curr_sum
        return res