Pergunta de entrevista da empresa Rakuten

Some string manipulation which I was trying to understand.