[Java] Solution Without Pre-Computation (Processing each query)
The below written code processes the curr lexicographically smallest string to find the next one.\nOne other way could be to pre-compute all possible strings fi
The below written code processes the curr lexicographically smallest string to find the next one.\nOne other way could be to pre-compute all possible strings first and then store them in an array of strings and then do each query in O(1).\n```\nclass CombinationIterator {\n    int[] str;\n    int n;\n    String ans = "";\n    boolean[] marked;\n    public CombinationIterator(String characters, int combinationLength) {\n        n = combinationLength;\n        ans = "";\n        str = new int[26];\n        marked = new boolean[26];\n        for(int i = 0; i < characters.length(); i++) str[characters.charAt(i) - \'a\'] = 1;    \n        for(int i = 0; i < 26; i++){\n            if(str[i] == 1){\n                ans += (char)(i + 97);\n                marked[i] = true;\n                if(ans.length() == n) break;\n            }\n        }\n    }\n    public boolean nextString(){\n        char[] aux = ans.toCharArray();\n        int flag = 0;\n        int ansIndex = -1;\n        l:for(int i = n - 1; i >= 0; i--){\n            int ne = 26;\n            if(i != n - 1) ne = ans.charAt(i + 1) - \'a\';\n            char c = ans.charAt(i); \n            int index = c - \'a\';\n            for(int j = index + 1; j < ne; j++){\n                if(!marked[j] && str[j] == 1){\n                    flag = 1;\n                    ansIndex = i;\n                    break l;\n                }\n            }\n        }\n        \n        if(flag == 0){\n            ans = ".";\n            return false;\n        }\n        for(int i = ansIndex; i < n; i++) marked[ans.charAt(i) - \'a\'] = false;\n        int p = ans.charAt(ansIndex) - \'a\' + 1;\n        for(int i = ansIndex; i < n; i++){\n            while(marked[p] || str[p] == 0) p++;\n            marked[p] = true;\n            aux[i] = (char)(p + 97);\n        }\n        ans = new String(aux);\n        return true;\n    } \n    public String next() {\n        String aux = new String(ans);\n        boolean b = nextString();\n        return aux; \n    }\n    public boolean hasNext() {\n        return !ans.equals(".");\n    }\n}\n\n/**\n * Your CombinationIterator object will be instantiated and called as such:\n * CombinationIterator obj = new CombinationIterator(characters, combinationLength);\n * String param_1 = obj.next();\n * boolean param_2 = obj.hasNext();\n */
[]