Pergunta de entrevista da empresa Amazon

In coding round I was asked the Next Permutation question from LeetCode but I had to find 5th next permutation. Follow up was to find the greatest possible permutation from the given digits.