Amazon interview question

To answer the technical question given.