본문 바로가기

~2023/Codility

Codility - Triangle Codility Lesson 6의 마지막 문제다. Triangle 이라는 문젠데, 배열 안에 3개의 수가 아래의 조건을 만족하는 지의 여부를 묻는 문제다. A[i] + A[j] > A[k] A[j] + A[k] > A[i] A[i] + A[k] > A[j] (단, 0 81%의 정답률 # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(A): # write your code in Py.. 더보기
Codility - NumberOfDiscIntersections 열심히 풀려고 하였으나, 반복문 2번 돌리는 거 외에는 생각이 잘 안났다.ㅜㅜ 결국 정답을 보고 이해하였지만, 앞으로도 열심히 해야겠다. 내 코드: 시간 복잡도: O(N ** 2) --> 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 count = 0 for i in range(len(A)): for j in range(i+1,len(A)): tmp = i+A[i] tmp2 = j-A[j] if tmp2 100%의 정답률 # you can write to stdout for debuggin.. 더보기
Codility - MaxProductOfThree 시간 복잡도: 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 A = sorted(A, reverse=True) if A[0]*A[1]*A[2] > A[0]*A[-1]*A[-2]: return A[0]*A[1]*A[2] else: return A[0]*A[-1]*A[-2] pass 관련 유튜브 강의도 있습니다~~!! https://www.youtube.com/watch?v=gFpzBTytLPY 저의 강의입니다ㅋㅋㅋ 더보기
Codility - Distinct # 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 if len(A) == 0: return 0 B = set(A) return len(B) pass 더보기
Codility - PassingCars # 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 east_car_num = 1 passing_car_num = 0 # 최초 동쪽으로 가는 차 위치 try: # 동쪽으로 가는 차가 없으면 에러 발생하여 passing_car가 없으므로 return 0 east_car = A.index(0) except: return 0 for i in range(east_car+1,len(A)): if A[i] == 1: passing_car_num += east_car_num if passing_car_num > 100000.. 더보기
Codility - MinAvgTwoSlice 20%의 정답률 코드ㅠㅠ # 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 tmp = sum(A[0:2])/len(A[0:2]) # step 2 - get the avaerage value in for loop A_length = len(A) for P in range(A_length): for Q in range(P+1,A_length-1): arr_ = A[P:Q+1] arr_sum = sum(arr_) arr_len = len(.. 더보기
Codility - GenomicRangeQuery 시간 복잡도: 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.appe.. 더보기
Codility - CountDiv 시간 복잡도: 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 fo.. 더보기