Amazon interview question

They asked to code an algorithm