Pregunta de entrevista de Morgan Stanley

Question on anagrams. Rewording strings in the most efficient way