Committing solution for problem 2.