Amazon Interview Question

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