Problem 2 solution