Problem 2 solution

Implementation for problem 2