Getting WA for every test case

code:https://ide.codingblocks.com/s/268165
it is working for given test case

@bhaskar0_0 your output is not always in dictionary order.
For eg for the input cbad
image
this sequence of output is wrong