Amazon interview question

Simple python coding and describing the solution