Solution to Number-Solitaire by codility

6 Sep

Question: https://codility.com/demo/take-sample-test/number_solitaire/

Question Name: Number-Solitaire or NumberSolitaire

The key point is: to achieve the position i, we can only come from the positions i-6, i-5, i-4, i-3, i-2, and i-1.

5 Replies to “Solution to Number-Solitaire by codility

  1. A more memory efficient solution can be achieved by only storing the last 6 values.

  2. I knew I can find a better solution here! 🙂 I didn’t realize that the space complexity can be reduced to O(1)! Hooray, Charles!
    Here is my boring text-book-like solution

Leave a Reply

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

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!