Adding solution for Problem 6