haven't tested on codility

grab the questions from someone's github
100% score on codility

fully tested, Time: O(n)