Klaviyo Interview Question

How to optimize this code