Skip to content

ghananigans/codility-lesson-solutions

Repository files navigation

My solutions to Codility's online lessons' tasks

All tasks and solutions will be sorted into the appropriate lessons, exactly like how codility organizes them.

Link to Lessons and tasks: https://codility.com/programmers/lessons/

Lesson 1: Iterations

BinaryGap

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

Lesson 2: Arrays

CyclicRotation

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

OddOccurrencesInArray

  • Find value that occurs in odd number of elements.

Lesson 3: Time Complexity

TapeEquilibrium

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

FrogJmp

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

PermMissingElem

  • Find the missing element in a given permutation.

Lesson 4: Counting Elements

FrogRiverOne

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

PermCheck

  • Check whether array A is a permutation.

MissingInteger

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

MaxCounters

  • 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

CountDiv

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

PassingCars

  • Count the number of passing cars on the road.

MinAvgTwoSlice

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

GenomicRangeQuery

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

Lesson 6: Sorting

MaxProductOfThree

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

Triangle

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

Distinct

  • Compute number of distinct values in an array.

NumberOfDiscIntersections

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

Lesson 7: Stacks and Queues

Nesting

  • Determine whether given string of parentheses is properly nested.

StoneWall

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

Brackets

  • Determine whether given string of parentheses is properly nested.

Fish

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

Lesson 8: Leader

Dominator

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

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.

Lesson 9: Maximum Slice Problem

MaxDoubleSliceSum

  • Find the maximal sum of any double slice.

MaxProfit

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

MaxSliceSum

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

Lesson 10: Prime and Composite Numbers

MinPerimeterRectangle

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

CountFactors

  • Count factors of a give number n.

Peaks

  • 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

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

Lesson 11: Sieve of Eratosthenes

CountSemiprimes

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

CountNonDivisible

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

Lesson 12: Euclidean algorithm

ChocolatesByNumbers

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

CommonPrimeDivisors

  • Check whether two numbers have the same prime divisors.

About

Answers to Codility's online lesson tasks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published