Goldman Sachs Interview Question

Based on string manipulation and patterns