Microsoft Interview Question

implement permutation function without using libraries