Pregunta de entrevista de Meta

Asked the next permutation problem.