## Solution to Brackets by codility

22 Jan

Question: http://codility.com/demo/take-sample-test/brackets Question Name: Brackets Classic application of stacks.

UPDATE (2016-07-19): Much appreciate Jeffrey’s comment and suggestion: I’m surprised so few people didn’t do a simple modulo at the start to check whether there is an even number of chars. … Read More »

## Solution to beta2010 (Number-Of-Disc-Intersections) by codility

22 Jan

Question: http://codility.com/demo/take-sample-test/number_of_disc_intersections Question Name: beta2010 or NumberOfDiscIntersections Interesting question. Does geometry matter here? Not much.

UPDATE on 2015/10/16: here is some pseudo-code to help you understand. Firstly, we convert the 2D problem into 1D. Because all the circles’ center … Read More »

## Solution to Triangle by codility

21 Jan

Question: http://codility.com/demo/take-sample-test/triangle Question Name: Triangle Update: we need two parts to prove our solution. On one hand, there is no false triangular. Since the array is sorted, we already know A[index] < = A[index+1] <= A[index+2], and all values are … Read More »

## Solution to Max-Product-Of-Three by codility

21 Jan

Question: http://codility.com/demo/take-sample-test/max_product_of_three Question Name: MaxProductOfThree An small trap: multiplying two negatives makes a positive number.

UPDATE on 03-02-2015: Thanks to @Julian, there is an O(N) solution. We sort the input in the original solution, because we want the two … Read More »

## Solution to Genomic-Range-Query by codility

21 Jan

Question: http://codility.com/demo/take-sample-test/genomic_range_query Question Name: GenomicRangeQuery This is a typical case that uses more space for less time.

## Solution to Passing-Cars by codility

20 Jan

Question: http://codility.com/demo/take-sample-test/passing_cars Question Name: PassingCars

## Solution to Max-Counters by codility

19 Jan

Question: http://codility.com/demo/take-sample-test/max_counters Question Name: MaxCounters A straightforward solution is easy as following. But the expected worst-case time complexity cannot be guaranteed.

We could use lazy-write to improve the performance. When receiving the max_counter command, we record the current-max value, … Read More »

## Solution to Frog-River-One by codility

19 Jan

Question: https://codility.com/demo/take-sample-test/frog_river_one Question Name: FrogRiverOne If coding with C, bitmap is preferred to store which positions are covered.

## Solution to Perm-Check by codility

19 Jan

Question: http://codility.com/demo/take-sample-test/perm_check Question Name: PermCheck This question is a simple variant of the counting question. The Python solution is:

The Java solution is:

## Solution to Tape-Equilibrium by codility

16 Jan

Question: http://codility.com/demo/take-sample-test/tape_equilibrium Question Name: TapeEquilibrium The variable of head stores the sum of the heading part of the tape. And the variable of tail stores the sum of tailing part. Then, we move the index from 2nd position to the … Read More »