Chapter2 coding interview problem 4.