Solution to Codility lesson5 Stone Wall problem, link to Codility problem and complete solution at the end of the post. Definitions: Context (from Codility): You are going to build a stone wall. It should have different heights in different places. The height of the wall is specified by a zero-indexed array H. H[I] is the height of […]

# Solutions

# Codility - Brackets

Solution to Codility lesson5 Brackets 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)" or "[U]" or "{U}" where U is a properly nested string; S has the form "VW" where V and W are properly nested strings. Problem: […]

# Codility - Fish

Solution to Codility lesson5-exercise2 Fish problem, link to Codility problem and complete solution at the end of the post. Definitions: Context (from Codility): You are given two non-empty zero-indexed arrays A and B consisting of N integers. Arrays A and B represent N voracious fish in a river, ordered downstream along the flow of the river.The fish […]

# Codility - Nesting

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 function solution […]

# 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), beyond input storage (not […]

# 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, only means that you can't use the same […]

# 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 the same, and only this. Problem: Define a function solution with […]

# 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 finding the minimal factor, such that A has factor 1, C has factor 2, […]

# 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 pairs in array A. If the count is […]

# 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 O(1); Expected worst-case space […]