본문 바로가기

Codility

(6)
Sorting / Distinct Write a functionclass Solution { public int solution(int[] A); }that, given a zero-indexed array A consisting of N integers, returns the number of distinct values in array A.Assume that:N is an integer within the range [0..100,000];each element of array A is an integer within the range [−1,000,000..1,000,000].For example, given array A consisting of six elements such that: A[0] = 2 A[1] = 1 A[2]..
Sorting / Triangle A zero-indexed 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[5] = 20Triplet (0, 2, 4) is triangular.Write a function:class Solution { public int solution(int[] A); }that, given a zero-indexed arra..
Counting Elements / MissingInteger This is a demo task.Write a function:class Solution { public int solution(int[] A); }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 inte..
Counting Elements / FrogRiverOne A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river.You are given a zero-indexed array A consisting of N integers representing the falling leaves. A[K] represents the position where one leaf falls at time K, measured i..
Counting Elements / PermCheck A non-empty zero-indexed 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] = 2is a permutation, but array A such that: A[0] = 4 A[1] = 1 A[2] = 3is not a permutation, because value 2 is missing.The goal is to check whether array A is a permutation.Write a fu..
Time Complexity / PermMissingElem 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.Write a function:class Solution { public int solution(int[] A); }that, given a zero-indexed array A, returns the value of the missing element.For example, given array A such that: A[0] ..