CDK Global interview question

Duplicates in string code, Optimization