problem from codility back in the day