2021 Dev-Matching - 웹 백앤드 개발자(상반기) - 로또의 최고 순위와 최저 순위 (Level 1)

 

https://programmers.co.kr/learn/courses/30/lessons/77484


Code

1
2
3
4
5
6
7
def solution(lottos, win_nums):
    n_unknowns = sum(map(lambda x: x == 0, lottos))
    chances    = set(win_nums) - set(lottos)
    min_pos    = len(win_nums) - len(chances)
    max_pos    = min_pos + min(len(win_nums) - min_pos, n_unknowns)
    get_rank = lambda pos: 7 - pos if pos >= 2 else 6
    return [get_rank(max_pos), get_rank(min_pos)]

Complexity

$O(|\text{win_nums}|)$