Pregunta de entrevista de Amazon

Fix some bugs in the code to make it work.