High-Flyer Quant interview question

implement all permutations of one sequence