Zscaler Interview Question

How can you optimize this set of code?