Chapter2 coding interview problem 3.