Pregunta de entrevista de Rakuten

Basic string repetition question and it's optimisation.