https://app.codility.com/programmers/lessons/4-counting_elements/
4. Counting Elements lesson - Learn to Code - Codility
Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.
app.codility.com
정답률: 100%
시간복잡도: O(N)
def solution(X, A):
check = [1] + [0] * X
cnt = 0
for K in range(len(A)):
if check[A[K]] == 0:
check[A[K]] = 1
cnt += 1
if cnt == X:
return K
if cnt != X:
return -1
728x90
반응형
'Problem Solving > Codility' 카테고리의 다른 글
[Python] 4.3. MissingInteger (0) | 2021.03.15 |
---|---|
[Python] 4.2. MaxCounters (0) | 2021.03.14 |
[Python] 3.3. TapeEquilibrium (0) | 2021.03.11 |
[Python] 3.2. PermMissingElem (0) | 2021.03.11 |
[Python] 3.1. FrogJmp (0) | 2021.03.07 |
댓글