Problem 3 solution