-
[알고리즘/자바스크립트] Codility, MaxSliceSum 문제 풀이Algorithm 2020. 5. 31. 22:16
MaxSliceSum A non-empty array A consisting of N integers is given. A pair of integers (P, Q), such that 0 ≤ P ≤ Q < N, is called a slice of array A. The sum of a slice (P, Q) is the total of A[P] + A[P+1] + ... + A[Q]. Write a function: function solution(A); that, given an array A consisting of N integers, returns the maximum sum of any slice of A. For example, given array A such that: [3, 2, -6..
-
[알고리즘/자바스크립트] Codility, Dominator 문제 풀이Algorithm 2020. 5. 24. 17:00
Dominator 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 [3, 4, 3, 2, 3, -1, 3, 3]. The dominator of A is 3 because it occurs in 5 out of 8 elements of A (namely in those with indices 0, 2, 4, 6 and 7) and 5 is more than a half of 8. Write a function function solution(..
-
[알고리즘/자바스크립트] Codility, PermCheck 문제 풀이Algorithm 2020. 5. 10. 12:30
Codility, PermCheck A non-empty array A consisting of N integers is given. A permutation is a sequence containing each element from 1 to N once, and only once. For example, array A such that: A[0] = 4 A[1] = 1 A[2] = 3 A[3] = 2 is a permutation, but array A such that: A[0] = 4 A[1] = 1 A[2] = 3 is not a permutation, because value 2 is missing. The goal is to check whether array A is a permutatio..
-
[알고리즘/자바스크립트] Codility, CyclicRotation 문제 풀이Algorithm 2019. 11. 29. 14:37
Codility, CyclicRotation An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the first place). The goal is to rotate array A K time..
-
[알고리즘/자바스크립트] Codility, OddOccurrencesInArray 문제 풀이Algorithm 2019. 11. 29. 14:22
Codility, OddOccurrencesInArray A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired. For example, in array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9 the elements at indexes 0 and 2..
-
[알고리즘/자바스크립트] Codility, Binary Gap 문제 풀이Algorithm 2019. 11. 27. 13:35
Codility, Binary Gap A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The n..