Solution to alpha2010 (Prefix-Set) by codility

29 Jan


Question Name: alpha2010 or PrefixSet

At the first glance, I think the set of Python is the best choice. Actually, the set solution passed all the test, and got 100/100 grade.

BUT, acording to the time complexity provided by Python Wiki, in the worst case, the time complexity of set solution should be O(n^2). The key to improve is the statement: “each element of array A is an integer within the range [0..N−1]”. I have to admit, the official solution is much much more elegant.

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!