반응형

시간 복잡도: 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
반응형
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(X, Y, D):
    # write your code in Python 3.6
    
    # step 1 - 방정식 문제로 풀 수 있겠다
    
    ########################
    # frog X >= frog Y
    # a를 구하면 되는 문제
    
    # X+a*D >= Y
    # a*D >= Y - X
    # a >= (Y - X)/D
    # ex) (85 - 10)/30
    # ex) (75)/30 = 2.5
    ########################
    
    
    a = (Y - X) / D
    
    # 딱 맞아떨어지면, int() 내장 함수를 써서, 2.0 -> 2로 변환 후 반환해줌
    if a % 1 == 0:
        return int(a)
    # 2.4 이렇게 소수로 떨어지면 int()를 통해 정수로 변환하는 '버림'을 하고 2로 만든 후 +1 해서 반환 
    else:
        return int(tmp) + 1
    
    
    pass
반응형

'Codility' 카테고리의 다른 글

Codility - TapeEquilibrium  (0) 2020.04.13
Codility - PermMissingElem  (0) 2020.04.12
Codility - OddOccurrencesInArray  (0) 2020.04.10
Codility - CyclicRotation  (0) 2020.04.09
Codility - Binary Gap  (0) 2020.04.08
반응형
# 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 - make a dictionary
    dict_= {}
    
    # step 2 - fill the dictionary
    for i in A:
        try: 
            dict_[i] += 1
        except: 
            dict_[i] =1
    
    # step 3 - find the odd value
    for i in dict_:
        if dict_[i] % 2 == 1:
            return i
    
    pass
반응형

'Codility' 카테고리의 다른 글

Codility - TapeEquilibrium  (0) 2020.04.13
Codility - PermMissingElem  (0) 2020.04.12
Codility - FrogJmp  (0) 2020.04.11
Codility - CyclicRotation  (0) 2020.04.09
Codility - Binary Gap  (0) 2020.04.08

+ Recent posts