## Solution to Ladder by codility

9 Mar

Question: https://codility.com/demo/take-sample-test/ladder Question Name: Ladder To solve this question, there are two key points. Firstly, for a given N rungs, the number of different ways of climbing is the (N+1)th element in the Fibonacci numbers. Naturally, we could get the … Read More »

## Solution to nu2011 (Double-Median) by codility

5 Mar

Question: https://codility.com/demo/take-sample-test/double_median Question Name: nu2011 or DoubleMedian For the given queries, we need to find the median in two sorted arrays of different lengths. Then we need to find out the median of the query results. That is, we need … Read More »

## Solution to oxygenium2014 (Count-Bounded-Slices) by codility

27 Feb

Question: https://codility.com/programmers/challenges/oxygenium2014 Question Name: oxygenium2014 or CountBoundedSlices For this question, I was unable to solve it with a golden answer. Instead, I tried to get two silver solutions. Both of them cheated the grading system to have the detected time … Read More »

## Solution to Common-Prime-Divisors by codility

18 Feb

Question: https://codility.com/demo/take-sample-test/common_prime_divisors Question Name: CommonPrimeDivisors

## Solution to Chocolates-By-Numbers by codility

17 Feb

Question: https://codility.com/demo/take-sample-test/chocolates_by_numbers Question Name: Chocolates-By-Numbers or ChocolatesByNumbers When we met with an empty wrapper, we must have been this position for twice. We use i for the first time and j for the second time. Due to the modulo feature, … Read More »

## Solution to upsilon2012 (Cartesian-Sequence) by codility

17 Feb

Question: https://codility.com/demo/take-sample-test/cartesian_sequence Question Name: upsilon2012 or CartesianSequence A straightforward solution would be construct the Cartesian tree, compute its height, and return the height plus one. But any left sub-tree would never be accessed or changed after its construction. And so … Read More »

## Solution to chi2012 (Cannonballs) by codility

7 Feb

Question: https://codility.com/demo/take-sample-test/chi2012/ Question Name: chi2012 or Cannonballs

## Solution to Min-Avg-Two-Slice by codility

6 Feb

Question: https://codility.com/demo/take-sample-test/min_avg_two_slice Question Name: MinAvgTwoSlice The key to solve this task is these two patterns: Â  (1) There must be some slices, with length of two or three, having the minimal average value among all the slices. (2) And all … Read More »

## Solution to gamma2011 (Count-Palindromic-Slices) by codility

5 Feb

Question: https://codility.com/demo/take-sample-test/count_palindromic_slices Question Name: CountPalindromicSlices This task is based on the longest palindromic substring question, which has a good solution naming Manacher’s algorithm. Some explanation about the algorithm could be found here (English) and here (Chinese).

## Solution to Array-Inversion-Count by codility

4 Feb

Question: https://codility.com/demo/take-sample-test/array_inversion_count Question Name: ArrayInversionCount

UPDATE on July 18, 2014: Thanks to @Andrew, there is another solution with Binary Indexed Tree. UPDATE on October 8, 2014: Thanks to @Piotrek Martynowicz, there was a bug for the statement: “computes the … Read More »