Amazon interview question

Random question you can practice with hacker rank