Amazon interview question

To solve a given problem with optimize coding