Published:
Updated:

  • 문제만 보면 우선 순위 큐를 써야 할 거 같은데 역시 프로그래머스라 단순 구현으로 풀린다.


Solution

import collections
from typing import List


def solution(priorities: List[int], location: int) -> int:
    answer = 0

    dq = collections.deque((index, process) for index, process in enumerate(priorities))
    while dq:
        current = dq.popleft()

        higher_priority_exists = False
        for q in dq:
            if current[1] < q[1]:
                higher_priority_exists = True
                continue

        if higher_priority_exists:
            dq.append(current)
            continue

        answer += 1
        if current[0] == location:
            break

    return answer


print(solution([2, 1, 3, 2], 2))
print(solution([1, 1, 9, 1, 1, 1], 0))


Reference

Leave a comment