Amazon interview question

Logica