Task Check whether two numbers have the same prime divisors.: A prime is a positive integer X that has exactly two distinct divisors: 1 and X. The first few prime integers are 2, 3, 5, 7, 11 and 13. A prime D is called a prime divisor of a positive integer P if there exists […]
Category: solutions
Task The task is to count the minimum number of nails that allow a series of planks to be nailed.: You are given two non-empty arrays A and B consisting of N integers. These arrays represent N planks. More precisely, A[K] is the start and B[K] the end of the K−th plank. Next, you are […]
Task The task is to search for the optimal solution to a problem involving summing Fibonacci numbers: A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position −1) and wants to get to the other bank (position N). The frog […]
Task The task is to Count the semiprime numbers in the given range [a..b]: A prime is a positive integer X that has exactly two distinct divisors: 1 and X. The first few prime integers are 2, 3, 5, 7, 11 and 13. A semiprime is a natural number that is the product of two […]
Codility: Peaks Solution Task Divide an array into the maximum number of same-sized blocks, each of which should contain an index P such that A[P – 1] < A[P] > A[P + 1]].: A non-empty array A consisting of N integers is given. A peak is an array element which is larger than its neighbors. […]
Codility: Count Factors Solution Task The task is to Count factors of given number n.: A positive integer D is a factor of a positive integer N if there exists an integer M such that N = D * M. For example, 6 is a factor of 24, because M = 4 satisfies the above […]
MaxDoubleSliceSum Solution Task The task is a variation of the Maximum subarray problem found in the max slice sum task: A non-empty array A consisting of N integers is given. A triplet (X, Y, Z), such that 0 ≤ X < Y < Z < N, is called a double slice. The sum of double […]
MaxSliceSum solution Task The task is to maximise the sum of a subsequence of an array. 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) […]
EquiLeader Solution Task The task is to count the number of values in an array that meet a condition: A non-empty array A consisting of N integers is given. The leader of this array is the value that occurs in more than half of the elements of A. An equi leader is an index S […]
StoneWall solution Task The task is to find a minimum number of rectangles that fulfil a criteria: You are going to build a stone wall. The wall should be straight and N meters long, and its thickness should be constant; however, it should have different heights in different places. The height of the wall is […]