Mphasis interview question

Coding and how you approach to solution