C++ | O(1) Time | Bit-Manipulation | Explanation with image | Very Easy
Using & operation, I will find all possible subsequences of s with length == combinationLength. Each string will  be added to vector v. \nThen, sort vector v in
Using & operation, I will find all possible subsequences of s with length == combinationLength. Each string will  be added to vector v. \nThen, sort vector v in reverse order.\nWhenever \'next\' is called , last string from v is returned and popped_back( ) from v.\nWhenever \'hasNext\' is called, return the bool value of whether v.size()==0\n\n\tclass CombinationIterator {\n\tpublic:\n    vector<string>v;\n    CombinationIterator(string s, int combinationLength) {\n    int tb = pow(2, s.size());\n\tfor (int i = 0; i < tb; ++i)                          //loop 1\n\t{\n\t\tint str = i, c = 0;       //keeps the count of set bits\n\t\twhile (str)                                            //loop2\n\t\t{\n\t\t\tif (str & 1)\n\t\t\t\tc++;\n\t\n\t\t\tstr = str >> 1;\n\t\t}\n\n\t\tif (c == combinationLength)                  //re-run the prev loop to generate the sequence \n\t\t{\n\t\t\tstr = i;\n\t\t\tstring a = "";\n\t\t\tint p = 0;\n\t\t\twhile (str)                             //loop3 \n\t\t\t{\n\t\t\t\tif (str & 1)\n\t\t\t\t\ta = s[s.size() - p - 1] + a;\n\t\n\t\t\t\tp++;\n\t\t\t\tstr = str >> 1;\n\t\t\t}\n\n\t\t\tv.push_back(a);                //add the subsequence to the vector\n\n\t\t}\n\t}\n            \n        sort(v.begin(),v.end(),greater<string>());             //sort in dec order, so that we can  easily snatch strings from back in lexographical order \n    }\n    \n\t//O(1) :-\n    string next() {\n        string s=v.back();\n           v.pop_back();\n            return s;\n    }\n    \n\t//O(1) :-\n    bool hasNext() {\n        return v.size()!=0;\n    }\n\t};\n\t\nMaximum bits = 32  (ignoring the fact that string length<=15 and can be greater)\nTotal time= loop1* ( loop2 + loop3) == 32* ((val<32) * (val<32)) ==constant time\n \nAny one wants to know the process of BitManipulation: ![image](https://assets.leetcode.com/users/images/05419d68-3134-488b-8d49-9e21abfd58c0_1636868599.9399881.jpeg)\n \nSo we count all the set bits for each number=>(0<number<32)  and generate subsequence from each of suitable setbit combinations.\n\n\nPlease **Upvote** if found it helpful!\nLet me know any doubts in the comments below! \nAll feedbacks are welcome\uD83D\uDE0A
['Bit Manipulation', 'C', 'C++']