3 test cases are passing and 1 is not
Hi Mudit,
Your code doesnot work for the case where the string is not in ascending and neither decending order for eg:
input: 231
output:
312
321
where as your code is giving output:
321
312
I guess that can only happen if i store elements in an arraylist and sort them with greater than given string and then print them. Give me another approach if you have one.
I did the question by passing the input string in sorted order and 1 argument as original order and it gave me the right answer. I want to know is there any better way which doesn’t includes sorting of the original string. You can check my code at this link https://ide.codingblocks.com/s/87444
Hi Mudit,
Your code is right and other way of doing this question pass the same string as two arguements say str and original without sorting it then compare character by character and when length of str becomes zero then compare the original and new string formed.
I was doing the question with the same approach as passing same string twice under different names and then forming subsequences and printing if it is only greater than the original string. But it was giving me wrong answer. Also can you please tell with sorting method does time complexity increases or decreases
Hi Mudit,
time complexity remains same whether you sort the string or not.