본문 바로가기

codility10

[Python] LongestPassword https://app.codility.com/demo/results/trainingPB6C9Y-2CD/ Test results - Codility You would like to set a password for a bank account. However, there are three restrictions on the format of the password: it has to contain only alphanumerical characters (a−z, A−Z, 0−9); there should be an even number of letters; there should be an app.codility.com Point 제시된 조건에 따라 validation check를 수행한다 스플릿 하여 fo.. 2021. 7. 18.
[Python] Leader https://codility.com/media/train/6-Leader.pdf Leader는 크기 N인 배열A 에서 과반수 이상 (N//2+1) 의 갯수를 가지고 있는 요소를 말한다. Leader를 조사하는 방법을 아래와 같이 정리하였다. 1. Sorting 정렬 후 중앙값의 카운트를 계산한다. 카운트가 n//2 보다 크다면 Leader에 해당한다. Detected time complexity O(N * log(N)) def solution(A): n = len(A) s_A = sorted(A) leader = None count = 0 for i in range(n): if s_A[i] == s_A[n//2]: count += 1 if count > n // 2: leader = s_A[n//2] .. 2021. 4. 5.
[Python] 8.1. Dominator https://app.codility.com/demo/results/trainingKJKX8S-C3B/ Test results - Codility An array A consisting of N integers is given. The dominator of array A is the value that occurs in more than half of the elements of A. For example, consider array A such that A[0] = 3 A[1] = 4 A[2] = 3 A[3] = 2 A[4] = 3 A[5] = -1 A[6] = 3 A[7] = 3 The dom app.codility.com Task Score 100% Correctness 100% Performan.. 2021. 4. 5.
[Python] 7.3. Nesting app.codility.com/demo/results/training6WQ7HN-NGN/ Test results - Codility A string S consisting of N characters is called properly nested if: S is empty; S has the form "(U)" where U is a properly nested string; S has the form "VW" where V and W are properly nested strings. For example, string "(()(())())" is properly nested but app.codility.com Task Score 100% Correctness 100% Performance 100% .. 2021. 3. 30.
[Python] 7.1. Brackets https://app.codility.com/demo/results/trainingU6MG2S-N29/ Test results - Codility A string S consisting of N characters is considered to be properly nested if any of the following conditions is true: S is empty; S has the form "(U)" or "[U]" or "{U}" where U is a properly nested string; S has the form "VW" where V and W are properly nes app.codility.com Task Score 100% Correctness 100% Performan.. 2021. 3. 27.
[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.
[Python] 4.3. MissingInteger 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 정답률: 100% (Task Score 100%, Correctness 100%, Performance 100%) 시간복잡도: O(N) or O(N * log(N)) def solution(A): _A = .. 2021. 3. 15.
[Python] 4.2. MaxCounters 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 정답률: 88% 시간복잡도:O(N + M) def solution(N, A): cnt = [0] * N maxcnt = 0 for K in range(len(A)): if A[K]-1 < N: cnt[A[K.. 2021. 3. 14.
[Python] 2.1. CyclicRotation https://app.codility.com/programmers/lessons/2-arrays/ 2. Arrays lesson - Learn to Code - Codility Rotate an array to the right by a given number of steps. app.codility.com 빈 배열이 들어올 경우에는 그대로 리턴한다 빈 배열이 아닌 경우 입력값 K에 대한 나머지를 구하고 다음 인덱스 값을 계산해준다 만약 다음 인덱스 값이 음수 일 경우, 배열의 크기를 더해서 인덱스 값을 보정해준다. def solution(A, K): if len(A) == 0: return A rotate = K % len(A) answer = [] for idx in range(len(A)): nex.. 2021. 3. 6.
728x90
반응형