Adding solution for Problem 5