Amazon interview question

Was asked to solve two questions in Coding round