Backtracking, Easy C++ ✅✅
Approach\n Describe your approach to solving the problem. \nUse Backtracking to generate all strings of length k and then return the answer of the query of next
# Approach\n<!-- Describe your approach to solving the problem. -->\nUse **Backtracking** to **generate** all strings of **length k** and then return the answer of the **query of next() and hashnext()**.\n\n# Complexity\n- Time complexity:O(N*K)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N*K)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass CombinationIterator {\npublic:\n    vector<string> v;\n    int k = 0;\n    void solve(string s,string p,int i,int len)\n    {\n       if(p.size()==len) \n       {\n           v.push_back(p);\n           return ;\n       }\n       if(i>=s.size()) return ;\n       p.push_back(s[i]);\n       solve(s,p,i+1,len);\n       p.pop_back();\n       solve(s,p,i+1,len);\n    }\n    CombinationIterator(string s, int len) {\n        solve(s,"",0,len);\n    }\n    string next() {\n        if(hasNext())  return v[k++];  \n        return "";\n    }\n    bool hasNext() {\n        if(k>v.size()-1) return false;\n        return true;\n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/6f543d78-cb97-493c-b641-f06d81a79e70_1689399330.3846827.jpeg)\n
['Backtracking', 'C++']