Problem 4 solution