Adding problem 8 coding approach