Salesforce interview question

solve an an online algorithm problem in hackerrank