Maluuba interview question

Coding assignment: optimize the performance of the provided code