Domanda di colloquio di Rakuten

Basic string repetition question and it's optimisation.