Adding solution to Problem 4