Pergunta de entrevista da empresa IBM

Coding questions from hackerank. two questions based on permutations