Second exercise from CtCI CH1.