Goldman Sachs Interview Question

algorithm on string