Problem with my code

This is the link to my code - https://ide.codingblocks.com/s/355053
My code is showing TLE for a 8 digit string, what should I do for that?

your code is correct but it is giving TLE in last 2 testcases
this is because of set

NOTE: DO NOT USE MAP OR SET.
So, please think of an approach that do not uses set or map.

Reference Code

In the code that you’ve referenced here, the global variable c’s value is 0 globally, how is it changing according to the operations in permute() when it’s used in the main(), won’t it use the global value here?
I’m a little confused with this, please help me out

Can somebody please reply to this post?

global variable can be changed from any function
in main() we are just using c not updating it

Okay, but the value of c that main() is using is not zero(global value), instead it is the changed value of c obtained from permute(), right?
This is bugging me, can you please explain how this works?

yes
we are increasing c in permute()
after complete execution of permute()
c will be the size of ans array
and then we use it in main()

So basically we’re using the updated value of c that is obtained from permute() in our main(), right?

So basically we’re using the updated value of c that is obtained from permute() in our main(), right?
yes