Algorithm
-
Lesson4. Counting Elements - PermCheckAlgorithm/codility 2018. 7. 23. 16:04
PermCheck - Check whether array A is a permutation.https://app.codility.com/programmers/lessons/4-counting_elements/perm_check/문제요약N개의 정수 배열 A가 있을 때, 1부터 N까지 한 번씩 나오면 permutation이라고 한다. A가 permutation이면 1, 아니면 0을 반환Assume that:N is an integer within the range [1..100,000];each element of array A is an integer within the range [1..1,000,000,000].Complexity:expected worst-case time complexity is O..
-
Lesson3. Time Complexity - PermMissingElemAlgorithm/codility 2018. 7. 23. 15:49
PermMissingElem - Find the missing element in a given permutation.https://app.codility.com/programmers/lessons/3-time_complexity/perm_missing_elem/문제요약길이가 N인 정수 배열 A가 있고, A가 1..(N+1)의 정수를 포함한다고 할 때 배열에 없는 하나의 정수를 찾아라.Assume that:N is an integer within the range [0..100,000];the elements of A are all distinct;each element of array A is an integer within the range [1..(N + 1)].Complexity:expected ..
-
Lesson3. Time Complexity - FrogJmpAlgorithm/codility 2018. 7. 23. 15:44
FrogJmp - Count minimal number of jumps from position X to Y.https://app.codility.com/programmers/lessons/3-time_complexity/frog_jmp/문제요약개구리가 X에서 Y이상으로 가려고 하고, 한 번에 고정된 길이 D만큼 점프를 한다고 하면 X에서 Y이상으로 가기 위한 최소 점프 수를 계산Assume that:X, Y and D are integers within the range [1..1,000,000,000];X ≤ Y.Complexity:expected worst-case time complexity is O(1);expected worst-case space complexity is O(1).풀이
-
Lesson2. Arrays - OddOccurrencesInArrayAlgorithm/codility 2018. 7. 23. 15:39
OddOccurrencesInArray - Find value that occurs in odd number of elements.https://app.codility.com/programmers/lessons/2-arrays/odd_occurrences_in_array/문제요약길이가 홀수인 정수 배열 A에서 한 숫자를 제외하고는 모두 두 개씩 짝으로 존재할 때, 짝이 되지 않는 숫자를 반환Assume that:N is an odd integer within the range [1..1,000,000];each element of array A is an integer within the range [1..1,000,000,000];all but one of the values in A occur an ..
-
Lesson2. Arrays - CyclicRotationAlgorithm/codility 2018. 7. 23. 15:33
CyclicRotation - Rotate an array to the right by a given number of steps.https://app.codility.com/programmers/lessons/2-arrays/cyclic_rotation/문제요약배열 A와 정수 K가 주어지면 A를 오른쪽으로 K번 shift해서 반환Assume that:N and K are integers within the range [0..100];each element of array A is an integer within the range [−1,000..1,000]. In your solution, focus on correctness. The performance of your solution will not..
-
Lesson1. Iteration - BinaryGapAlgorithm/codility 2018. 7. 23. 15:24
BinaryGap - Find longest sequence of zeros in binary representation of an integer.https://app.codility.com/programmers/lessons/1-iterations/binary_gap/문제요약양의 정수 N의 2진 표현에서 1로 감싸진 연속된 0의 최대 갯수를 계산. 포함하지 않으면 0을 반환Assume that:N is an integer within the range [1..2,147,483,647].Complexity:expected worst-case time complexity is O(log(N));expected worst-case space complexity is O(1).풀이각 자리 bit를 검사하면 l..
-
A사 코딜리티 문제Algorithm/problems 2018. 7. 19. 14:44
A사 코딜리티 문제 - 난이도(하), 결과(100%)문제1입력 N의 각 자리 숫자들을 재정렬해서 만들 수 있는 가장 큰 수를 반환풀이각 자릿수를 list로 쪼갠다음 내림차순 정렬 후 다시 이어주면 된다.python으로 더 간단하게(return int(''.join(sorted(str(N), reverse=True)))도 가능) 가능하다 일단 제출은 변환하는 부분도 같이 작성.문제2N개의 나무의 높이 A가 주어지면, 이 중 하나만 제거해서 오름차순으로 정렬할 수 있는 경우의 수 반환. 불가능하면 0반환풀이처음에는 각 자리를 제거해서 오름차순이 되는지 계산하는 단순한 방법을 사용했으나, 더 나은 방법을 찾아서 제출했다. 하나만 제거해서 오름차순이 된다는건 높이가 감소하는 부분이 전체에 1개 이하로 존재해야 ..