Adding solution for Problem 2