Moon Active Interview Question

How I implemented the solution