Intuit interview question

1. How to optimize the code