Microsoft Interview Question

Optimization Question: optimize code I wrote in interview