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 […]
Category: coding
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 […]
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 […]
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 […]