Amazon interview question

first part is a debugging assesment, second part is a programming one