Zscaler interview question

How can you optimize this set of code?