Amazon interview question

Advance coding test for the initial phase