Adding a solution for Problem 4