KidsLoop interview question

Solve this hacker rank test