https://programmers.co.kr/learn/courses/30/lessons/42587
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def solution(priorities, location):
answer = 0
p = priorities # alias
p_sorted = list(sorted(p))[::-1]
idxs = list(range(len(p)))
while len(p) > 0:
cur_p = p.pop(0)
cur_i = idxs.pop(0)
if cur_p == p_sorted[0]: # max priority
p_sorted.pop(0)
answer += 1
if cur_i == location:
return answer
else:
p.append(cur_p)
idxs.append(cur_i)
return answer
Complexity
$O(nlogn)$
- $n$ = len(priorities)
- $m$ = len(location)
PREVIOUSEtc