UPSUB - Up Subsequence
If x = a0a1a2...an-1 is a string where ai denotes the character at index i, a subsequence aj0aj1aj2...ajn is called an upsubsequence if aj0 <= aj1 <= aj2 <= ... <= ajn and j0 < j1 < j2 < ... < jn.
A maximal upsubsequence of a string is defined as the upsubsequence of maximum length. BuggyD observes that a string x can have many maximal upsubsequences. Help him find all the maximal upsubsequences in x.
The first line of the input contains an integer t, the number of test cases. t test cases follow.
Each test case consists of a single line containing a string x, where the length of x is no more than 100. x will not contain any spaces, tabs or other whitespace characters.
For each test csae, output all of the maximal upsubsequences of x in lexicographical order. Print a blank line after each test case.
Input: 1 abcbcbcd Output: abbbcd abbccd abcccd
solve TRIP first :D :D
moving backwards will automatically give sorted order :)
I am not sure why the problem is giving wrong answer inspite of covering all the cases...Can some one kindly give some hints or a test case where there is chance of getting wrong answer..
You forgot to place a '\n' character at the end of the file! Please correct.