Codility challenge