목록Study/Programming (86)
메모장 입니다2
1.개요 -codility를 풀다가, python을 사용하는 중에 sort 라이브러리의 time complexity를 알아야 했다. 2.해답 Worst case performance O(nlogn)Best case performance O(n) Average case performance O(nlogn) Worst case space complexity O(n) 3.링크 스택오버플로우https://stackoverflow.com/questions/25813774/complexity-of-python-sort-method
1.문제 설명 Nucleotides of types A, C, G and Thave impact factors of 1, 2, 3 and 4, respectively. ....For example, consider string S = CAGCCTA and arrays P, Q such that: P[0] = 2 Q[0] = 4 P[1] = 5 Q[1] = 5 P[2] = 0 Q[2] = 6The answers to these M = 3 queries are as follows:The part of the DNA between positions 2 and 4 contains nucleotides Gand C (twice), whose impact factors are 3 and 2 respectively,..
1. 설명 Write a functiondef solution(A)that, given a zero-indexed array A consisting of N integers, returns the number of distinct values in array A. For example, given array A consisting of six elements such that: A[0] = 2 A[1] = 1 A[2] = 1 A[3] = 2 A[4] = 3 A[5] = 1the function should return 3, because there are 3 distinct values appearing in array A, namely 1, 2 and 3. -숫자의 종류 수 구하기.-해쉬셋 이용하면 너..
1. 문제 설명 For example, array A such that: A[0] = 4 A[1] = 2 A[2] = 2 A[3] = 5 A[4] = 1 A[5] = 5 A[6] = 8contains the following example slices:slice (1, 2), whose average is (2 + 2) / 2 = 2;slice (3, 4), whose average is (5 + 1) / 2 = 3;slice (1, 4), whose average is (2 + 2 + 5 + 1) / 4 = 2.5.The goal is to find the starting position of a slice whose average is minimal.-평균값은 소수까지 구해서 비교되는 것 주의. >2..
1. 설명 that, given three integers A, B and K, returns the number of integers within the range [A..B] that are divisible by K, i.e.:{ i : A ≤ i ≤ B, i mod K = 0 }For example, for A = 6, B = 11 and K = 2, your function should return 3, because there are three numbers divisible by 2 within the range [6..11], namely 6, 8 and 10.> 배수의 수>시간 복잡도 O(1) 2.소스 // you can use includes, for example: // #includ..
1. 설명 that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.Given A = [1, 2, 3], the function should return 4.Given A = [−1, −3], the function should return 1.Assume that:N is an integer within the range [1..100,000];each element of array A is an integer within ..
1.설명 A zero-indexed array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing.Your goal is to find that missing element. A[0] = 2 A[1] = 3 A[2] = 1 A[3] = 5the function should return 4, as it is the missing element. 2.소스// you can use includes, for example: // #include // you can write to stdout for..
1.문제 설명 The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|In other words, it is the absolute difference between the sum of the first part and the sum of the second part.For example, consider array A such that: A[0] = 3 A[1] = 1 A[2] = 2 A[3] = 4 A[4] = 3We can split this tape in four places:P = 1, difference = |3 − 10| = 7 ..