Practice problem in the book "Cracking the coding interview".