Pergunta de entrevista da empresa Rakuten

Basic string repetition question and it's optimisation.