Categories
coding solutions

Codility: Equileader Solution

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 […]

Categories
coding solutions

Codility: StoneWall Solution

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 […]

Categories
coding solutions

NumberOfDiscIntersections O(N) Solution

NumberOfDiscIntersections O(N) solution Task The task is to count overlapping discs given an array of radii We draw N discs on a plane. The discs are numbered from 0 to N − 1. An array A of N non-negative integers, specifying the radiuses of the discs, is given. The J-th disc is drawn with its […]

Categories
coding solutions

Codility: PassingCars Solution

PassingCars Task The task is to count pairs of zeros and ones, where the 1 comes after the 0. Array A contains only 0s and/or 1s: 0 represents a car traveling east, 1 represents a car traveling west. The goal is to count passing cars. We say that a pair of cars (P, Q), where […]

Categories
coding solutions

Codility: MinAvgTwoSlice Solution

MinAvgTwoSlice Task The task is to find the slice of an array with the minimum average Write a function: int solution(vector<int> &A); that, given a non-empty array A consisting of N integers, returns the starting position of the slice with the minimal average. If there is more than one slice with a minimal average, you […]

Categories
coding solutions

Codility: GenomicRangeQuery Solution

GenomicRangeQuery Task The task is to find the minimum values in slices of an array. A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which correspond to the types of successive nucleotides in the sequence. Each nucleotide has an impact factor, which is an integer. Nucleotides […]

Categories
coding solutions

Codility: CountDiv Solution

CountDiv Task This is a division task. This is classified as ‘Respectable’, but is simple. Write a function: int solution(int A, int B, int K); 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 ≤ […]

Categories
coding solutions

Codility: PermCheck Solution

PermCheck Solution Task The task is to calculate if an array contains all the numbers from 1 to N, where N is the size of the array: 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, […]

Categories
coding solutions

Codility: MaxCounters Solution

MaxCounters Task This task is a functional operation task, involving commands that can operate on all items in an array: You are given N counters, initially set to 0, and you have two possible operations on them: increase(X) − counter X is increased by 1, max counter − all counters are set to the maximum […]

Categories
coding solutions

Codility: TapeEquilibrium Solution

Tape Equilibrium Task Task is to find the minimum difference in the sums of the values in an array, before and after a pivot point A non-empty array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 < P < N, splits this tape […]