Sponsored
Use these hints if you're stuck. Try solving on your own first.
Can we solve this problem using DP with bit masking?
You just need two states in DP which are last_ind in the permutation and the mask of numbers already used.
Solve with full IDE support and test cases