Microsoft interview question

Optimization Question: optimize code I wrote in interview