Amazon interview question

Q. Solve the given coding problems.