another solution for problem7