1.3 All Subsequence

Print all subsequence of a set with duplicate letters

Input: String set {abbbc} with size n

Output: List<String> res

Solution:

  1. n levels of the recursion tree, each level consider adding a letter or not

  2. 2 states/branches: add or not

  3. Skip the duplicate letters and move on to the next unique letter

IMPORTANT: Sort the array first, and add condition while going down the tree

char[] array = set.toCharArray();

Arrays.sort(array);

while (index < input.length - 1 && array[index+1] == array[index] {

index++;

}

Last updated

Was this helpful?