app.codility.com/demo/results/trainingWVD5AJ-4CG/
Task Score
100%
Correctness
100%
Performance
100%
Detected time complexity
O(N)
def solution(A, B):
stack = []
cnt = 0
for i in range(len(A)):
if B[i] == 1:
stack.append(A[i])
else:
while stack:
f = stack[-1]
if f > A[i]:
break
else:
stack.pop()
if not stack:
cnt += 1
return cnt + len(stack)
문제를 푸는데 도움이 된 테스트 케이스
728x90
반응형
'Problem Solving > Codility' 카테고리의 다른 글
[Python] 8.1. Dominator (0) | 2021.04.05 |
---|---|
[Python] 7.3. Nesting (0) | 2021.03.30 |
[Python] 7.1. Brackets (0) | 2021.03.27 |
[Python] 6.4. Triangle (0) | 2021.03.26 |
[Python] 6.3. NumberOfDiscIntersections (0) | 2021.03.25 |
댓글