본문 바로가기
Problem Solving/Codility

[Python] 4.2. MaxCounters

by 부르르 2021. 3. 14.

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


정답률: 88%

시간복잡도:O(N + M)

def solution(N, A):

    cnt = [0] * N
    maxcnt = 0

    for K in range(len(A)):
        if A[K]-1 < N:
            cnt[A[K]-1] += 1
            if cnt[A[K]-1] > maxcnt:
                maxcnt = cnt[A[K]-1]
        else:
            cnt = [maxcnt] * N

    return cnt
728x90
반응형

'Problem Solving > Codility' 카테고리의 다른 글

[Python] 4.4. PermCheck  (0) 2021.03.15
[Python] 4.3. MissingInteger  (0) 2021.03.15
[Python] 4.1. FrogRiverOne  (0) 2021.03.13
[Python] 3.3. TapeEquilibrium  (0) 2021.03.11
[Python] 3.2. PermMissingElem  (0) 2021.03.11

댓글