HubSpot interview question

How would you reduce the O(n) complexity?