Add more efficient solution to problem 5.