WeShape Interview Question

How would you optimize the code?