Skip to content

hungyennn/Codility-Lessons-Exercises-Solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My solutions to Codility's online lessons tests.

I will update this repository regularly.
Most of them are lessons task, and some are exercises tasks (in Exercises folder).

Lesson 1: Iterations

BinaryGap (Easy)

  • Find longest sequence of zeros in binary representation of an integer.

Lesson 2: Arrays

CyclicRotation (Easy)

  • Rotate an array to the right by a given number of steps.

OddOccurrencesInArray (Easy)

  • Find value that occurs in odd number of elements.

Lesson 3: Time Complexity

FrogJmp (Easy)

  • Count minimal number of jumps from position X to Y.

PermMissingElem (Easy)

  • Find the missing element in a given permutation.

TapeEquilibrium (Easy)

  • Minimize the value |(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|.

Lesson 4: Counting Elements

FrogRiverOne (Easy)

  • Find the earliest time when a frog can jump to the other side of a river.

PermCheck (Easy)

  • Check whether array A is a permutation.

MissingInteger (Medium)

  • Find the minimal positive integer not occuring in a given sequence.

MaxCounters (Medium)

  • Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.

Lesson 5: Prefix Sums

PassingCars (Easy)

  • Count the number of passing cars on the road.

CountDiv (Medium)

  • Compute number of integers divisible by k in range [a..b].

MinAvgTwoSlice (Medium)

  • Find the minimal average of any slice containing at least two elements.

GenomicRangeQuery (Medium)

  • Find the minimal nucleotide from a range of sequence DNA.

Lesson 6: Sorting

Distinct (Easy)

  • Compute number of distinct values in an array.

MaxProductOfThree (Easy)

  • Maximize A[P]*A[Q]*A[R] for any triplet (P, Q, R).

Triangle (Easy)

  • Determine whether a triangle can be built from a given set of edges.

NumberOfDiscIntersections (Medium)

  • Compute the number of intersections in a sequence of discs.

Lesson 7: Stacks and Queues

Brackets (Easy)

  • Determine whether given string of parentheses is properly nested.

Fish (Easy)

  • N voracious fish are moving along a river. Calculate how many fish are still alive.

Nesting (Easy)

  • Determine whether given string of parentheses is properly nested.

StoneWall (Easy)

  • Cover "Manhattan skyline" using the minimum number of rectangles.

Lesson 8: Leader

Dominator (Easy)

  • Find an index of an array such that its value occurs at more than half of indices in the array.

EquiLeader (Easy)

  • 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.

Lesson 9: Maximum Slice Problem

MaxProfit (Easy)

  • Given a log of stock prices compute the maximum possible earning.

MaxSliceSum (Easy)

  • Find a maximum sum of a compact subsequence of array elements.

MaxDoubleSliceSum (Medium)

  • Find the maximal sum of any double slice.

Lesson 10: Prime and Composite Numbers

MinPerimeterRectangle (Easy)

  • Find the minimal perimeter of any rectangle whose area equals N.

CountFactors (Easy)

  • Count factors of a give number n.

Peaks (Medium)

  • 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].

Flags (Medium)

  • Find the maximum number of flags that can be set on mountain peaks.

Lesson 11: Sieve of Eratosthenes

CountNonDivisible (Medium)

  • Calculate the number of elements of an array that are not divisors of each element.

CountSemiprimes (Medium)

  • Count the semiprime numbers in the given range [a..b].

Lesson 12: Euclidean algorithm

ChocolatesByNumbers (Easy)

  • There are N chocolates in a circle. Count the number of chocolates you will eat.

CommonPrimeDivisors (Medium)

  • Check whether two numbers have the same prime divisors.

Lesson 13: Fibonacci numbers

FibFrog (Medium)

  • Count the minimum number of jumps required for a frog to get to the other side of a river.

Ladder (Medium)

  • Count the number of different ways of climbing to the top of a ladder.

Lesson 14: Binary search algorithm

MinMaxDivision (Medium)

  • Divide array A into K blocks and minimize the largest sum of any block.

NailingPlanks (Medium)

  • Count the minimum number of nails that allow a series of planks to be nailed.

Lesson 15: Caterpillar method

AbsDistinct (Easy)

  • Compute number of distinct absolute values of sorted array elements.

CountDistinctSlices (Easy)

  • Count the number of distinct slices (containing only unique numbers).

CountTriangles (Easy)

  • Count the number of triangles that can be built from a given set of edges.

MinAbsSumOfTwo (Medium)

  • Find the minimal absolute value of a sum of two elements.

Lesson 16: Greedy algorithms

MaxNonoverlappingSegments (Easy)

  • Find a maximal set of non-overlapping segments.

TieRopes (Easy)

  • Tie adjacent ropes to achieve the maximum number of ropes of length >= K.

Lesson 17: Dynamic programming

NumberSolitaire (Medium)

  • In a given array, find the subset of maximal sum in which the distance between consecutive elements is at most 6.

MinAbsSum (Hard)

  • Given array of integers, find the lowest absolute sum of elements.

Releases

No releases published

Packages

No packages published

Languages