Design the CombinationIterator class:


	CombinationIterator(string characters, int combinationLength) Initializes the object with a string characters of sorted distinct lowercase English letters and a number combinationLength as arguments.
	next() Returns the next combination of length combinationLength in lexicographical order.
	hasNext() Returns true if and only if there exists a next combination.


&nbsp;
Example 1:

Input
["CombinationIterator", "next", "hasNext", "next", "hasNext", "next", "hasNext"]
[["abc", 2], [], [], [], [], [], []]
Output
[null, "ab", true, "ac", true, "bc", false]

Explanation
CombinationIterator itr = new CombinationIterator("abc", 2);
itr.next();    // return "ab"
itr.hasNext(); // return True
itr.next();    // return "ac"
itr.hasNext(); // return True
itr.next();    // return "bc"
itr.hasNext(); // return False


&nbsp;
Constraints:


	1 &lt;= combinationLength &lt;= characters.length &lt;= 15
	All the characters of characters are unique.
	At most 104 calls will be made to next and hasNext.
	It is guaranteed that all calls of the function next are valid.


class CombinationIterator:

    def __init__(self, characters: str, combinationLength: int):
        res = []
        def dfs(low, path):
            if len(path) == combinationLength:
                res.append(path)
                return
            for idx in range(low, len(characters)):
                dfs(idx+1, path+characters[idx])
        
        dfs(0, "")
        self.combinations = res
        self.currIdx = 0
            
    def next(self) -> str:
        self.currIdx += 1
        return self.combinations[self.currIdx-1]

    def hasNext(self) -> bool:
        return self.currIdx <= len(self.combinations) - 1
class CombinationIterator {

    private Queue<String> allCombinations;
    public CombinationIterator(String characters, int combinationLength) {
        this.allCombinations = new LinkedList<>();
        generateAllCombinations(characters,0,combinationLength,new StringBuilder());
    }
    
    private void generateAllCombinations(String characters,int index,int combinationLength,StringBuilder currentString){
        
        if(currentString.length() == combinationLength){
            this.allCombinations.offer(currentString.toString());
            return;
        }
        
        for(int i = index ; i < characters.length() ; i++){
            currentString.append(characters.charAt(i));
            generateAllCombinations(characters,i+1,combinationLength,currentString);
            currentString.deleteCharAt(currentString.length()-1);
        }
        
    }
    
    public String next() {
        return this.allCombinations.poll();
    }
    
    public boolean hasNext() {
      return !this.allCombinations.isEmpty();
    }
}
class CombinationIterator {
public:
	vector<string>ans;
	int j=0;
	void comb(int i,string& s,int k,string& t){
		if(i==s.size()){
			if(t.size()==k) ans.push_back(t);
			return;
		}
//      Pick
		t.push_back(s[i]);
		comb(i+1,s,k,t);
		t.pop_back();
//      NotPick
		comb(i+1,s,k,t);
	}

	CombinationIterator(string characters, int combinationLength) {
		sort(characters.begin(),characters.end());
		string t="";
		comb(0,characters,combinationLength,t);
	}

	string next() {
		return ans[j++];
	}

	bool hasNext() {
		if(j==ans.size())return false;
		return true;
	}
};
var CombinationIterator = function(characters, combinationLength) {
    this.stack = Array.from({ length: combinationLength }, (_, i) => i);
    this.combinationLength = combinationLength;
    this.characters = characters;
};

CombinationIterator.prototype.next = function() {
    const word = this.stack.map((i) => this.characters[i]).join("");

    for (let lastIndex = this.characters.length - 1; this.stack.at(-1) == lastIndex; )
        lastIndex = this.stack.pop() - 1;

    if (this.stack.length > 0)
        for (let i = this.stack.pop() + 1; this.stack.length < this.combinationLength; i++)
            this.stack.push(i);
    
    return word;
};

CombinationIterator.prototype.hasNext = function() {
    return this.stack.length > 0;
};
Iterator for Combination