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 worked, and gave the right answer. But I could only get 95/100, because of the TIMEOUT ERROR in the large_constantSpace test set. This bad solution is show as below.

Then, I tried to solve it by finding out the Lexicographically Minimal Rotation (LMR). At that time, I did not know the term “LMR” being a classic problem, and use a brute force method. Reasonably, I still did not get the 100/100 until google it. After reading couple of articles, with the improved algorithm to find LMR, the final solution gets the 100/100.

Leave a Reply

Your email address will not be published. Required fields are marked *