Pregunta de entrevista de IBM

Coding questions from hackerank. two questions based on permutations