Implementation for problem 2.