반응형

시간 복잡도: O(N + M) --> 100%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(S, P, Q):
    # write your code in Python 3.6
    
    # step 1 - input array S,P,Q
    # already succeed
    
    # step 2 - get range from array P,Q
    M = len(P)
    
    return_arr = []
    
    # step 3 - do the job(for senetence)
    for i in range(M):
        arr = S[P[i]:Q[i]+1]
        try:
            arr.index('A')
            return_arr.append(1)
        except:
            try:
                arr.index('C')
                return_arr.append(2)
            except:
                try:
                    arr.index('G')
                    return_arr.append(3)
                except:
                    return_arr.append(4)
                    
    return return_arr
        
    pass
반응형

'Codility' 카테고리의 다른 글

Codility - PassingCars  (0) 2020.04.20
Codility - MinAvgTwoSlice  (0) 2020.04.19
Codility - CountDiv  (0) 2020.04.18
Codility - PermCheck  (0) 2020.04.18
Codility - MissingInteger  (0) 2020.04.17
반응형

시간 복잡도: O(B-A) --> 50%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A, B, K):
    # write your code in Python 3.6
    
    # step 1 - input A,B,K
    # already succeed
    
    # step 2 - do the for sentence
    return_value = 0
    
    for i in range(A,B+1):
        if i % K == 0:
            return_value += 1
            
    return return_value
    pass

시간 복잡도: O(1) --> 100%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A, B, K):
    # write your code in Python 3.6
    
    start_num = A/K
    end_num = int(B/K)
    
    if start_num%1 != 0:
        start_num = int(start_num) + 1
    else:
        start_num = int(start_num)
    
        
    return end_num - (start_num-1)
    pass

 

반응형

'Codility' 카테고리의 다른 글

Codility - MinAvgTwoSlice  (0) 2020.04.19
Codility - GenomicRangeQuery  (0) 2020.04.19
Codility - PermCheck  (0) 2020.04.18
Codility - MissingInteger  (0) 2020.04.17
Codility - MaxCounters  (0) 2020.04.15
반응형

시간 복잡도: O(N) or O(N * log(N)) --> 100%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    # write your code in Python 3.6
    
    # step 1 - get input A
    # already succeed
    
    # step 2 - sorting A, which is consist of positive integer
    A = sorted(A)
    
    # step 3 - do the job(for sentence)
    a = 1
    
    for i in A:
        if i == a:
            a += 1
        else:
            return 0
            
    return 1
    
    
    pass
반응형

'Codility' 카테고리의 다른 글

Codility - GenomicRangeQuery  (0) 2020.04.19
Codility - CountDiv  (0) 2020.04.18
Codility - MissingInteger  (0) 2020.04.17
Codility - MaxCounters  (0) 2020.04.15
Codility - FrogRiverOne  (0) 2020.04.13
반응형

시간 복잡도: O(N) or O(N * log(N)) --> 77%의 정답률 (Wrong answer 가 있었음)

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    # write your code in Python 3.6
    
    # step 1 - input array A
    # already succeed
    
    # step 2 - find the smallest positive integer of A
    
    # sorting A
    A = sorted(A)
    
    # find the positive integer
    try:
        a = A.index(1)
        tmp = A[a:]
        tmp = set(tmp)
    except:
        return 1
        
    b = 1
    
    for i in tmp:
        if i == b:
            b += 1
        else:
            return b
            
    return b
        
    
    pass

시간 복잡도: O(N) or O(N * log(N)) --> 100%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    # write your code in Python 3.6
    
    # step 1 - input array A
    # already succeed
    
    # step 2 - find the smallest positive integer of A
    
    # sorting A
    A = set(A)
    A = sorted(A)
    
    # find the positive integer
    try:
        a = A.index(1)
        tmp = A[a:]
    except:
        return 1
        
    b = 1
    
    for i in tmp:
        if i == b:
            b += 1
        else:
            return b
            
    return b
        
    
    pass
반응형

'Codility' 카테고리의 다른 글

Codility - CountDiv  (0) 2020.04.18
Codility - PermCheck  (0) 2020.04.18
Codility - MaxCounters  (0) 2020.04.15
Codility - FrogRiverOne  (0) 2020.04.13
Codility - TapeEquilibrium  (0) 2020.04.13
반응형

시간 복잡도: O(N*M) --> 66%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(N, A):
    # write your code in Python 3.6
    
    # step 1 - make a arr, consist of int '0', length is N
    tmp = [0]*N
    
    # do the job along case
    for i in A:
        if i <= N and i >= 1:
            tmp[i-1] += 1
            continue
        if i == N + 1:
            tmp = [max(tmp)]*N
    
    
    return tmp
        
            
    pass

시간 복잡도: O(N*M) --> 66%의 정답률

 

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(N, A):
    # write your code in Python 3.6
    
    # step 1 - input N,A
    # already succeed
    
    # step 2 - get for setence
    tmp = [0]*N
    
    for i in A:
        try:
            tmp[i-1] += 1
        except:
            tmp = [max(tmp)]*N
    return tmp
    
    
    pass

 

다른 사람의 코드 : 시간 복잡도: O(N+M) --> 100%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N, A):
    # write your code in Python 3.6
    
    # step 1 - input N,A
    # already succeed
    
    # step 2 - get for setence
    counters = N * [0]
    next_max_counter =  max_counter = 0
    
    for oper in A:
        try:
            current_counter = counters[oper-1] = max(counters[oper-1] +1, max_counter+1)
            next_max_counter = max(current_counter, next_max_counter)
        except:
            max_counter = next_max_counter
    
    
    return [c if c > max_counter else max_counter for c in counters]
    
    
    pass
반응형

'Codility' 카테고리의 다른 글

Codility - PermCheck  (0) 2020.04.18
Codility - MissingInteger  (0) 2020.04.17
Codility - FrogRiverOne  (0) 2020.04.13
Codility - TapeEquilibrium  (0) 2020.04.13
Codility - PermMissingElem  (0) 2020.04.12
반응형

시간 복잡도: O(N**2) --> 54%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(X, A):
    # write your code in Python 3.6
    
    # step 1 - input x,a
    # already succeed
    
    # step 2 - if 1,2,3,.. in arr then, change the index into 0
    # else: continue
    
    arr = list(range(1,X+1))
    
    for i in range(len(A)):
        if A[i] in arr:
            arr[A[i]-1] = 0
            if sum(arr) == 0:
                return i
           
    pass

 

시간 복잡도: O(N) --> 100%의 정답률

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(X, A):
    # write your code in Python 3.6
    
    # step 1 - input x,a
    # already succeed
    
    # step 2 - # step 2 - if 1,2,3,.. in arr then, change the index into 0
    # else: continue
    
    check = [0] * X
    check_sum = 0
    
    for i in range(len(A)):
        if check[A[i]-1] == 0:
            check[A[i]-1] = 1
            check_sum += 1
            
            if check_sum == X:
                return i
                
    return -1
        
    pass

 

반응형

'Codility' 카테고리의 다른 글

Codility - MissingInteger  (0) 2020.04.17
Codility - MaxCounters  (0) 2020.04.15
Codility - TapeEquilibrium  (0) 2020.04.13
Codility - PermMissingElem  (0) 2020.04.12
Codility - FrogJmp  (0) 2020.04.11
반응형

처음 코드(53% 정답률) 

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    # write your code in Python 3.6

    # step 1 - if length of A ==  2
    if len(A) == 2:
        return abs(A[0]-A[1])
        
    # step 2 - create a array
    arr_ = []
    
    # step 3 - get a difference between the sum of two part using iteration
    for i in range(1,len(A)):
        tmp = abs(sum(A[:i])-sum(A[i:]))
        arr_.append(tmp)
        
    return min(arr_)
        
    pass

 

 

정답 코드

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    # write your code in Python 3.6

    # step 1 - if length of A ==  2
    if len(A) == 2:
        return abs(A[0]-A[1])
        
    # step 2 - create a array
    arr_ = []
    
    tmp_1 = 0
    tmp_2 = sum(A)
    
    # step 3 - get a difference between the sum of two part using iteration
    for i in range(len(A)-1):
        tmp_1 = tmp_1 + A[i]
        tmp_2 = tmp_2 - A[i]
        arr_.append(abs(tmp_1 - tmp_2))
        
        
    return min(arr_)
        
        
    pass
반응형

'Codility' 카테고리의 다른 글

Codility - MaxCounters  (0) 2020.04.15
Codility - FrogRiverOne  (0) 2020.04.13
Codility - PermMissingElem  (0) 2020.04.12
Codility - FrogJmp  (0) 2020.04.11
Codility - OddOccurrencesInArray  (0) 2020.04.10
반응형
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A):
    # write your code in Python 3.6
    
    # step 1 - sort the array by acsend way
    A = sorted(A)
    
    # step 2 - find the missing one in range 1 ~ len(A)+1
    for i in range(0,len(A)):
        if i+1 != A[i]:
            return i+1
            
    return len(A)+1
            
    pass

 

반응형

'Codility' 카테고리의 다른 글

Codility - FrogRiverOne  (0) 2020.04.13
Codility - TapeEquilibrium  (0) 2020.04.13
Codility - FrogJmp  (0) 2020.04.11
Codility - OddOccurrencesInArray  (0) 2020.04.10
Codility - CyclicRotation  (0) 2020.04.09

+ Recent posts