added the solution for Problem 4