KidsLoop Interview Question

Solve this hacker rank test