How do i solve this question

I have prepared one solution which makes all possible permutations and only prints the required ones but it gets error probably due to memory exceeding

@tusharnitharwal
hello tushar,
give it a try ,it will work

is this the best solution?

@tusharnitharwal
no not best.u can do some optimisations like instead of storing all permuations u can only store valid strings .this will use some less space.

Yes, i made that optimisation. I though it would help in reducing the size of the array but it still is showing error for 2 test cases

@tusharnitharwal
plese share ur code using cding blocks ide

@tusharnitharwal
tushar number of valid strings can be more than the size of ur array .so instead of using array use vector

I was using string of strings. By hit and trial, i set the size of string of string as 220k and it got passed.
I just want to know whether there is another more efficient solution to this problem.

@tusharnitharwal
In editorial they have mentioned some solution . I am sure about its algorithm. but i think that is space efficient

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.