Solution for simple algorithmic problem.