American Express interview question

Explain your solution to the assignment