Tricky permutations tle error


check my code . It’s give timelimit error on last test case

permutating with recusrsion takes time, so you can solve this last test case using inbuilt next_permutation function