본문 바로가기

Problem Solving/Codility27

[Python] 6.4. Triangle https://app.codility.com/demo/results/trainingX6JCFR-MQJ/ Test results - Codility An array A consisting of N integers is given. A triplet (P, Q, R) is triangular if 0 ≤ P A[R], A[Q] + A[R] > A[P], A[R] + A[P] > A[Q]. For example, consider array A such that: A[0] = 10 A[1] = 2 A[2] = 5 A[3] = 1 A[4] = 8 A app.codility.com 인풋 데이터의 사이즈가 10만 아래이기 때문에 완전탐색하기로 결정하였다. 순열을.. 2021. 3. 26.
[Python] 6.3. NumberOfDiscIntersections https://app.codility.com/programmers/lessons/6-sorting/ 6. Sorting lesson - Learn to Code - Codility Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R). app.codility.com 1차시도 Task Score 50% Correctness 100% Performance 0% Detected time complexity O(N**2) def solution(A): cnt = 0 for i in range(len(A)): for j in range(i+1, len(A)): if max(A[j], A[i]) >= j-i or j-i 10 ** 7: return -1 return cnt 2021. 3. 25.
[Python] 6.2. MaxProductOfThree https://app.codility.com/programmers/lessons/6-sorting/ 6. Sorting lesson - Learn to Code - Codility Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R). app.codility.com Task Score 100% Correctness 100% Performance 100% Detected time complexity O(N * log(N)) def solution(A): _A = sorted(A) return max(_A[0]*_A[1]*_A[-1], _A[-3]*_A[-2]*_A[-1]) 2021. 3. 25.
[Python] 6.1. Distinct https://app.codility.com/programmers/lessons/6-sorting/ 6. Sorting lesson - Learn to Code - Codility Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R). app.codility.com Task Score 100% Correctness 100% Performance 100% Time Complexity O(N*log(N)) or O(N) def solution(A): return len(set(A)) 2021. 3. 25.
[Python] 5.4. PassingCars https://app.codility.com/programmers/lessons/5-prefix_sums/ 5. Prefix Sums lesson - Learn to Code - Codility Compute number of integers divisible by k in range [a..b]. app.codility.com Task Score 100% Correctness 100% Performance 100% 시간복잡도 O(N) def solution(A): east = [] for i in range(len(A)): if A[i] == 0: east.append(i) if len(east) == 0: return 0 prefix_sum = [] for i in range(len(east)-1):.. 2021. 3. 24.
[Python] 5.3. MinAvgTwoSlice https://app.codility.com/programmers/lessons/5-prefix_sums/ 5. Prefix Sums lesson - Learn to Code - Codility Compute number of integers divisible by k in range [a..b]. app.codility.com 1차 시도 Task Score 50% Correctness 100% Performance 0% 시간복잡도 O(N ** 3) def solution(A): N = len(A) prefix_sum = [A.copy() for _ in range(N)] min_val = 10 ** 10 answer = N for p in range(N): for q in range(p+1,N): if.. 2021. 3. 18.
[Python] 5.2. GenomicRangeQuery app.codility.com/programmers/lessons/5-prefix_sums/ 5. Prefix Sums lesson - Learn to Code - Codility Compute number of integers divisible by k in range [a..b]. app.codility.com 1차 시도 Task Score 62% Correctness 100% Performance 0% 시간복잡도 O(N*M) def solution(S, P, Q): impact_factor = {"A":1,"C":2,"G":3,"T":4} lst = [] for K in range(len(P)): queries = set(S[P[K]:Q[K]+1]) min_val = 9 for q in querie.. 2021. 3. 16.
[Python] 5.1. CountDiv https://app.codility.com/programmers/lessons/5-prefix_sums/ 5. Prefix Sums lesson - Learn to Code - Codility Compute number of integers divisible by k in range [a..b]. app.codility.com Task Score: 100% Correctness: 100% Performance:100% 시간복잡도: O(1) def solution(A, B, K): answer = 0 if A == 0: answer += 1 if A 2021. 3. 15.
[Python] 4.4. PermCheck 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 Task Score 100% Correctness 100% Performance 100% 시간복잡도 O(N) or O(N * log(N)) def solution(A): _A = sorted(A) _B = .. 2021. 3. 15.
728x90
반응형