Generate all subsequence as Preprocessing. Concise code
\tclass CombinationIterator {\n\t\t//Used list to store all words with length as given\n\t\tList list = new ArrayList<>();\n\t\tint pointer = 0;\n\t\t//function
\tclass CombinationIterator {\n\t\t//Used list to store all words with length as given\n\t\tList<String> list = new ArrayList<>();\n\t\tint pointer = 0;\n\t\t//function to generate all words of length k\n\t\tpublic void generate(char c[], int len) {\n\t\t\tint n = c.length;\n\t\t\tfor (int i = 0; i < 1<<n; i++) {\n\t\t\t\tStringBuilder sb = new StringBuilder("");\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tif ((i&(1 << j)) != 0) sb.append(c[j]);\n\t\t\t\t}\n\t\t\t\tif (sb.toString().length() == len) list.add(sb.toString());\n\t\t\t}\n\t\t\tCollections.sort(list);\n\t\t}\n\t\tpublic CombinationIterator(String characters, int combinationLength) {\n\t\t\tgenerate(characters.toCharArray(), combinationLength);\n\t\t}\n\t\tpublic String next() {\n\t\t\treturn list.get(pointer++);\n\t\t}\n\t\tpublic boolean hasNext() {\n\t\t\treturn pointer >= list.size() ? false : true;\n\t\t}\n\t}
['Bitmask', 'Java']