Salesforce Interview Question

Continue to optimize the algorithm complexity