Actually your question is to list all subsets from a given set.
Considering the set {a,a,a,d,d,d,c,g,h,z,z}, your goal is to list all its unique subsets in order, except the empty set: {a} {a,a} {a,a,a} {a,a,a,d}
There is a quick way to list all subsets from a given set.
Let's take {ABC} as example:
{} = 000
{C} = 001
{B} = 010
{BC} = 011
{A} = 100
{AC} = 101
{AB} = 110
{ABC} = 111
See the pattern? Simply use an integer that grows from 0 to 2^n - 1. If the i'th digit of the integer is 1, fetch the i'th element from the set.
Note: Since in your example, there are duplicates in the string; therefore after generation you might need to remove duplicates.
Hope this can help you.