Pergunta de entrevista da empresa F5

Some variation of Permutations II from LeetCode