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 »

Solution to omega2013 (Falling-Disks) by codility

4 Feb

Question: https://codility.com/demo/take-sample-test/falling_disks Question Name: omega2013 or FallingDisks

Solution to Equi by codility

2 Feb

Question: https://codility.com/demo/take-sample-test/equi Question Name: Equi The expected worst-case space complexity could be less than required.

Solution to lithium2013 (Clocks) by codility

2 Feb

Question: https://codility.com/demo/take-sample-test/clocks Question Name: lithium2013 or Clocks At the very beginning, I found this task is very similar with the string rotation question in CTCI. And I did transfer this question into a string rotation one. The string rotation solution … Read More »

Solution to Tree-Height by codility

29 Jan

Question: https://codility.com/demo/take-sample-test/tree_height Question Name: TreeHeight Classic recursion problem.