Salesforce interview question

Continue to optimize the algorithm complexity