This repository includes my solutions to the problems of the Codility lessons. The sources are in Java, and each source file contains a description of the algorithm used.
Lessons | My Solutions | Difficulty | |
---|---|---|---|
1 | 1-Iterations (pdf) | BinaryGap: Find longest sequence of zeros in binary representation of an integer. | Painless [100%] |
2 | 2-Arrays (pdf) | CyclicRotation: Rotate an array to the right by a given number of steps. | Painless [100%] |
3 | 2-Arrays (pdf) | OddOccurrencesInArray: Find value that occurs in odd number of elements. | Painless [100%] |
4 | 3-Time Complexity (pdf) | FrogJmp: Count minimal number of jumps from position X to Y. | Painless [100%] |
5 | 3-Time Complexity (pdf) | PermMissingElem: Find the missing element in a given permutation. | Painless [100%] |
6 | 3-Time Complexity (pdf) | TapeEquilibrium: Minimize the value |(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|. | Painless [100%] |
7 | 4-Counting Elements (pdf) | PermCheck: Check whether array A is a permutation. | Painless[100%] |
8 | 4-Counting Elements (pdf) | FrogRiverOne: Find the earliest time when a frog can jump to the other side of a river. | Painless[100%] |
9:heavy_check_mark: | 4-Counting Elements (pdf) | MaxCounters: Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum. | Respectable[100%] |
10 | 4-Counting Elements (pdf) | MissingInteger: Find the smallest positive integer that does not occur in a given sequence. | Respectable[100%] |
11 | 5-Prefix Sums (pdf) | PassingCars: Count the number of passing cars on the road. | Painless[100%] |
12 | 5-Prefix Sums (pdf) | CountDiv: Compute number of integers divisible by k in range [a..b] | Painless [100%] |
13:heavy_check_mark: | 5-Prefix Sums (pdf) | MinAvgTwoSlice: Find the minimal average of any slice containing at least two elements. | Respectable[100%] |
14:heavy_check_mark: | 5-Prefix Sums (pdf) | GenomicRangeQuery: Find the minimal nucleotide from a range of sequence DNA. | Respectable[100%] |
15 | 6-Sorting (pdf) | MaxProductOfThree: Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R). | Painless[100%] |
16 | 6-Sorting (pdf) | Distinct: Compute number of distinct values in an array. | Painless[100%] |
17 | 6-Sorting (pdf) | Triangle: Determine whether a triangle can be built from a given set of edges. | Painless[100%] |
18:heavy_check_mark: | 6-Sorting (pdf) | NumberOfDiscIntersections: Compute the number of intersections in a sequence of discs. | Respectable[100%] |
19 | 7-Stacks and Queues (pdf) | Brackets: Determine whether a given string of parentheses (multiple types) is properly nested. | Painless[100%] |
20 | 7-Stacks and Queues (pdf) | Nesting: Determine whether a given string of parentheses (single type) is properly nested. | Painless[100%] |
21:heavy_check_mark: | 7-Stacks and Queues (pdf) | Fish: N voracious fish are moving along a river. Calculate how many fish are alive. | Painless[100%] |
22:heavy_check_mark: | 7-Stacks and Queues (pdf) | StoneWall: Cover "Manhattan skyline" using the minimum number of rectangles. | Painless[100%] |
23:heavy_check_mark: | 8-Leader (pdf) | EquiLeader: Find the index S such that the leaders of the sequences A[0], A[1], ..., A[S] and A[S + 1], A[S + 2], ..., A[N - 1] are the same. | Painless[100%] |
24 | 8-Leader (pdf) | Dominator: Find an index of an array such that its value occurs at more than half of indices in the array. | Painless[100%] |
25 | 9-Maximum slice problem (pdf) | MaxProfit: Given a log of stock prices compute the maximum possible earning. | Painless[100%] |
26 | 9-Maximum slice problem (pdf) | MaxSliceSum: Find a maximum sum of a compact subsequence of array elements. | Painless[100%] |
27:heavy_check_mark: | 9-Maximum slice problem (pdf) | MaxDoubleSliceSum: Find the maximal sum of any double slice. | Respectable[100%] |
28 | 10-Prime and composite numbers (pdf) | MinPerimeterRectangle: Find the minimal perimeter of any rectangle whose area equals N. | Painless[100%] |
29 | 10-Prime and composite numbers (pdf) | CountFactors: Count factors of given number n. | Painless[100%] |
30 | 10-Prime and composite numbers (pdf) | [Peaks:] | [100%] |
31:heavy_check_mark: | 10-Prime and composite numbers (pdf) | Flags: Find the maximum number of flags that can be set on mountain peaks. | Respectable[100%] |
32:heavy_check_mark: | 11-Sieve of Eratosthenes (pdf) | CountSemiprimes: Count the semiprime numbers in the given range [a..b] | Respectable[100%] |
33 | 11-Sieve of Eratosthenes (pdf) | [CountNonDivisible:] | [100%] |
34 | 12-Euclidean algorithm (pdf) | ChocolatesByNumbers: There are N chocolates in a circle. Count the number of chocolates you will eat. | Painless[100%] |
35 | 12-Euclidean algorithm (pdf) | [CommonPrimeDivisors:] | [100%] |
36 | 13-Fibonacci numbers (pdf) | [Ladder:] | [100%] |
37 | 13-Fibonacci numbers (pdf) | [FibFrog:] | [100%] |
38:heavy_check_mark: | 14-Binary search algorithm (pdf) | MinMaxDivision: Divide array A into K blocks and minimize the largest sum of any block. | Respectable[100%] |
39:heavy_check_mark: | 14-Binary search algorithm (pdf) | NailingPlanks: Count the minimum number of nails that allow a series of planks to be nailed. | Respectable[100%] |
40 | 15-Caterpillar method (pdf) | AbsDistinct: Compute number of distinct absolute values of sorted array elements. | Painless[100%] |
41:heavy_check_mark: | 15-Caterpillar method (pdf) | CountDistinctSlices: Count the number of distinct slices (containing only unique numbers). | Painless[100%] |
42 | 15-Caterpillar method (pdf) | CountTriangles: Count the number of triangles that can be built from a given set of edges. | Painless[100%] |
43 | 15-Caterpillar method (pdf) | MinAbsSumOfTwo: Find the minimal absolute value of a sum of two elements. | Painless[100%] |
44 | 16-Greedy algorithms (pdf) | MaxNonoverlappingSegments: Find a maximal set of non-overlapping segments. | Painless[100%] |
45 | 16-Greedy algorithms (pdf) | TieRopes: Tie adjacent ropes to achieve the maximum number of ropes of length >= K. | Painless[100%] |
46 | 17-Dynamic programming (pdf) | [NumberSolitaire:] | [100%] |
47:heavy_check_mark: | 17-Dynamic programming (pdf) | MinAbsSum: Given array of integers, find the lowest absolute sum of elements. | Ambitious[100%] |
48 | 99-Future training | [TreeHeight:] | [100%] |
49 | 99-Future training | [OddOccurrencesInArray:] | [100%] |
50 | 99-Future training | [BinaryGap:] | [100%] |
51 | 99-Future training | [StrSymmetryPoint:] | [100%] |
52 | 99-Future training | [ArrayInversionCount:] | [100%] |