I am not able to understand question

Explain logic and code both