IBM Interview Question

Coding questions from hackerank. two questions based on permutations