Fast Enterprises Interview Question

Optimize the code you constructed