Is this an inefficient approach as i have used all the combinations and then iterated over them
Should we only make the combinations that are required??
I have used arraylist here and generating all possible combinations
@bhavik911,
That is a little inefficient.
The problem is exactly similar to the one in which you are generating all of the permutations of given string and all you need to do is to keep track of the original String too and in the base case just check the answer to be printed must be larger than original String.
Can you please explain me the editorial solution I dont really get it
And why do we even need to keep flag as a parameterr
Please explain(reaching limit)
@bhavik911,
We first sort all the chars. If flag is true, add char to osf and call the function again. Else, if char at i is greater than char at 0 (we construct the next larger string) then flag becomes true. If the char is smaller, don’t call anything.
But we are not even changing value of flag to true here ? why is it needed
@bhavik911,
We are changing the value in flag. Look carefully we have passed a condition in one of the recursive calls