Added solution for problem 5 and added utility functions