Solution to Codility lesson5-exercise1 Nesting problem, link to Codility problem and complete solution at the end of the post. Definitions: Properly nested string S: S is empty; S has the form “(U)” where U is a properly nested string; S has the form “VW” where V and W are properly nested strings. Problem: Define a […]

# Codility – Distinct

Solution to Codility lesson4-exercise3 Distinct problem, link to Codility problem and complete solution at the end of the post. Definitions: Problem: Define a function solution with input A , such that solution returns the number of distinct values in array A. Expected worst-case time complexity is O(N*log(N)); Expected worst-case space complexity is O(N), […]

# Codility – Triangle

Solution to Codility lesson4-exercise2 Triangle problem, link to Codility problem and complete solution at the end of the post. Definitions: A triplet is triangular if and: A[P] + A[Q] > A[R], A[Q] + A[R] > A[P], A[R] + A[P] > A[Q]. Just like in the Max Product of Three problem, […]

# Codility – Max Product of Three

Solution to Codility lesson4-exercise1 Max Product of Three problem, link to Codility problem and complete solution at the end of the post. Definitions: Product: Product of three elements of A, , such that . Notice that saying that , it’s the same that saying that the elements can’t be […]

# Codility – Genomic Range Query

Solution to Codility lesson3-exercise3 Genomic Range Query problem, link to Codility problem and complete solution at the end of the post. Definitions: S: string of size N, consisting of characters A, C, G and T. Query: Consists in analyzing the substring S[P[K]] to S[Q[K]] with , and […]

# Codility – Passing Cars

Solution to Codility lesson3-exercise2 Passing Cars problem, link to Codility problem and complete solution at the end of the post. Definitions: Pair: A pair can be described by a tuple , such that ; Problem: Define a function solution with input A, such that solution returns the numbers of […]

# Codility – Count Divisible

Solution to Codility lesson3-exercise1 Count Divisible problem, link to Codility problem and complete solution at the end of the post. Definitions: Problem: Define a function solution with input A, B and K, such that solution returns the number of integers divisible by K , belonging to the interval [A, B]. Expected worst-case time complexity is […]

# Codility – Number Solitaire

Solution to Codility lesson15-exercise1 Number Solitarie problem, link to Codility problem and complete solution at the end of the post. Assume that: Definitions: Problem: Starting at index 0. The initial result is the value of the element at index 0. From index i we can move from 1 to 6 indexes, we’ll call this difference k. Then […]

# Codility – Max Counters

Solution to Codility lesson2-exercise4 Max Counters problem, link to Codility problem and complete solution at the end of the post. Definitions: In this problem we have the definition of two operations, with a given N, and a count array for counting elements from 1 to N , […]

# Codility – Missing Integer

Solution to Codility lesson2-exercise3 Missing Integer problem, link to Codility problem and complete solution at the end of the post. Definitions: Problem: Define a function solution with input A, such that solution returns the minimal positive integer (greater than 0) that does not belongs to A. Expected worst-case time complexity is O(N); Expected worst-case […]