Added problem 3 implementation.