Pergunta de entrevista da empresa Bjak

Was asked a string manipulation problem,