No same permutation

I am getting the wrong answer I don’t know why
Please help.
code : https://ide.codingblocks.com/s/194448

@SWIFTY,
I think you are not considering the fact that there could be duplicates. But in case you are considering it, can you please tell what does your issafe function do?

insafe fuction is checking whether there are any two same number, if two numbers are not same then swap otherwise dont swap,its giving correct ans for 1 1 3 or 3 1 1