Pergunta de entrevista da empresa SAP

Solve a coding problem. It was on strings again