[C++] prev_permutation to calc char positions + sol with pointers
I consider here 2 solutions: \n with built-in permutations, 24 ms\n with pointers, 16 ms (faster but it would be harder to implement during an interview)\n# 1. 
I consider here 2 solutions: \n* with built-in permutations, 24 ms\n* with pointers, 16 ms (faster but it would be harder to implement during an interview)\n# 1. **Built-in permutations**\n**Intuition**\n* we can either take or skip each char: 0 or 1\n* the total number of chars remains: it\'s the combination length - N\n* the 1st combo is the first N chars\n\n**Example**\n```\nabcd, 2\n1100 next=ab           // all 1\'s at the beginning\n1010 next=ac\n1001 next=ad\n0110 next=bc\n0101 next=bd\n0011 next=cd           // all 1\'s at the end\n```\n\nSo we just count permutations backwards moving all 1\'s from the beginnning to the end.\n\nIf you would like to try it:\n```\n["CombinationIterator","next","hasNext","next","hasNext","next","hasNext","next","hasNext","next","hasNext","next","hasNext"]\n[["abcd",2],[],[],[],[],[],[],[],[],[],[],[],[]]\n```\n\nNow we can use standard C++ method: ```prev_permutation()``` which also returns bool to say if the next combo exists.\nThat\'s the answer we need for our ```hasNext()``` method:\n```\nclass CombinationIterator {\npublic:\n    vector<bool> combo; // index in chars -> true if chars[i] is a part of the next combination\n    bool hasNextBool;\n    string chars;\n    int n; // combination length\n    \n    CombinationIterator(string characters, int combinationLength) {\n        chars=characters;\n        n=combinationLength;\n        combo.resize(chars.size());\n        for(int i=0;i<n;i++) combo[i]=true; // first n symbols - 1st combo\n        hasNextBool=chars.size()>=n; // if we have enough chars for at least one combination\n    }\n    \n    string next() {\n        string res="";\n        for(int i=0;i<combo.size();i++)\n            if(combo[i])\n                res+=chars[i];\n        hasNextBool = prev_permutation(begin(combo), end(combo)); // get ready for the next iteration\n        return res;\n    }\n\n    bool hasNext() {\n        return hasNextBool;       \n    }\n};\n```\n**Speed**\n24 ms\nThe solution was inspired by @yubowenok, #10 in the [biwikly contest 15](https://leetcode.com/contest/biweekly-contest-15/ranking)\n\n# 2. **Pointers**\n\n**Intuition**\n* We need to select several chars from the array maintaining their order since they both are ordered lexicographically\n* We can keep an index of chars currently used\n* the pointer to the 1st char can only move right (to the end)\n* the pointer to the last char should stay within the range of chars (stay < ```n```)\n* other pointers have to stay in range between 2 adjacent pointers\n\nExample\n```\nabcde, n=3\n^  ^  ^\ncombo=014  = abe\ne - cannot move right\nb - has space to move right; all chars after it are take leftmost positions\ncombo=023  = acd\n```\n\nFull solution:\n```\nclass CombinationIterator {\npublic:\n    string chars;\n    int n; // combo size\n    int nchars; // chars size\n    string res; // last returned result\n    vector<int> combo; // size=n; at start set to 1st chars, eg 0,1,2 for n=3\n    CombinationIterator(string characters, int combinationLength) {\n        res="";\n        n=combinationLength;\n        chars=characters;\n        nchars=chars.size();\n        combo.resize(n);\n        for(int i=0;i<n;i++) combo[i]=i; // initial N chars match the beginning of "chars"\n    }\n    \n    string next() {\n        if(res.size()==0) {\n            res=chars.substr(0,n);\n            return res;\n        }\n        for(int i=n-1;i>=0;i--) { // find the last symbol we can increase\n            if(combo[i]!=nchars-1) {\n                if (i==n-1 || combo[i]+1<combo[i+1]) { \n                    combo[i++]++; // take next char and set remaining chars to the nearest\n                    for(;i<n;i++) { // e.g. "abcde",3: abe -> acd\n                        combo[i]=combo[i-1]+1;\n                    }\n                    break;\n                }\n            }\n        }\n        res="";\n        for(int i:combo)  res+=chars[i]; // compose string\n        return res;\n    }\n    \n    bool hasNext() {\n        return res.size()==0||res[0]!=chars[chars.size()-n]; // e.g. chars=abCd, res=Cd       \n    }\n};\n```
['C']