Hello, I am trying to generate all permutations and for each permutation I am checking if the given conditions are satisfied and then counting it as part of the solution. But this approach times out as the time complexity is n*n!
I am not able to understand as to what can be precomputed.
Any help is appreciated.
Thanks in advance