Klaviyo Interview Question

Find a bug and refactor the code.