almatar Interview Question

Solving an mid difficulty problem