Solution for codility chalanges