TRICKY PERMUTATIONS one tle

questioon = https://hack.codingblocks.com/contests/c/452/737
solution = https://ide.codingblocks.com/#/s/23430

https://ide.codingblocks.com/#/s/23564

its giving right answer for only 2 test cases rest are wrong