본문 바로가기

CodingTest/Level2

[연습]코딩테스트-프린터

코딩테스트연습

  • programmers.co.kr
  • 프린터



def solution(priorities, location):
    answer = {}

    d = {x : priorities[x] for x in range(len(priorities))}
    while 1:
        if len(answer) == len(priorities):
            break
        c = max(list(d.values()))
        p = list(d.items())[0]
        if p[1] == c:
            d.pop(p[0])
            answer[p[0]] = p[1]
        else:
            d.pop(p[0])
            d[p[0]] = p[1]

    cnt = 1
    for x,y in answer.items():
        if x == location:
            return (cnt)
        else:
            cnt += 1
    return (cnt)

solution([2,1,3,2], 2)
반응형