CodeArray interview question

Explain about your code, its approach