Salesforce interview question

I was asked to explain my approach and write code for it.