Amazon Interview Question

Problem faced with past project.