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 […]
Tag: solutions
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 […]
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 […]
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 ≤ […]
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, […]
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 […]
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 […]
Cyclic Rotation Task Again, this is a simple task: Write a function: vector<int> solution(vector<int> &A, int K); that, given an array A consisting of N integers and an integer K, returns the array A rotated K times. Solution You just calculate the previous index of each element and populate the answer accordingly #include <iostream> using […]
Binary Gap Task This is a simple task: 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. You simply have to find the length of the maximum run of zeros in the binary representation of […]
Codility Lessons Solutions Codility is a company that provides testing of candidates coding skills. Essentially their site asks the applicant to write a function to perform a task, then runs unit tests against the answer. There is a post about their site here. They also provide a set of tasks that anyone can take and […]