본문 바로가기

~2023/Codility

Codility - PermCheck 시간 복잡도: 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 - MissingInteger 시간 복잡도: 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) .. 더보기
Codility - MaxCounters 시간 복잡도: 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 = 1: tmp[i-1] += 1 continue if i == N + 1: tmp = [max(tmp)]*N return tmp pass 시간 복잡도: O(N*M) --> 66%의 정답률 # you can writ.. 더보기
Codility - FrogRiverOne 시간 복잡도: 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 pas.. 더보기
Codility - TapeEquilibrium 처음 코드(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_.app.. 더보기
Codility - PermMissingElem # 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 - FrogJmp # 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로 변환 .. 더보기
Codility - OddOccurrencesInArray # 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 더보기