Added teacher's solution as a reference.