Amazon interview question

Explain your idea before approaching a question, and proving it is optimized