answer for question 8.1 of cracking the coding interview