Added code for the solution.

Solved the problem and am submitting for evaluation.