[Python] Simple Mathematical + Pythonic Solution
Key Hint : Since we need non repeting the combinations in a lexiographic order, one analogus series we can consider is the binary numbers\n\nBasically, if you t
**Key Hint** : Since we need non repeting the combinations in a lexiographic order, one analogus series we can consider is the binary numbers\n\nBasically, if you take abc for example, and we need the lexiographic combinations of 2 letters, the answer would be ab, ac and bc\n\nComparing with our analogy,\nIf you consider abc as 111, and start from 2<sup>3</sup> -1 = 7 (111) and go till 0 (000)\n\nThe numbers with two 1s and their represntations in characters are\n110 - ab \n101 - ac\n011 - bc\n\nNow knowing that, we have 2 operations to consider, \n1. Check if there are more such combinations\n2. Return The combination\n\n\n---\n<br>\n\n#### For the first part of the question,\nwe are looking for numbers with two 1s in a 3 digit series:\n\n> If you\'re familiar with **Permutations and Combinations**:\n> - you might have guessed it that it\'s **<sup>3</sup>C<sub>2</sub>**\n\n> If you\'re not,\n>> the first 1 in the two 1s has 3 different places to sit on\n>  - basically, it could be 100, 010 or 001\n\n>>Similarly the second 1 has 2 places to sit on (since one of the spots has already been occupied)\n> - making it 110,101 (for 100) 011,110 (for 010) 101,010 (for 001) = 6\n\n> >As you can already see, we have each occurance appear twice so, we divide it by two\n> - making it 3 x 2 / 2  or *n x (n-1) / r*\n> >  where n is the total number of characters, and r is the required number of characters\n\n> Now wrapping it up, the equation can be generalized as **n!/r!(n-r)!**\n> If the current combination is lesser than the above value, hasNext returns **True**, else **False**\n\n#### For the second part of the question,\n> We just need to return characters depending on our analogy by **looping through binary numbers in the decending order**\n\n\n---\n<br>\n\n```from math import comb\nclass CombinationIterator:\n\n    def __init__(self, characters: str, combinationLength: int):\n        self.len = combinationLength         \n        self.characters = characters\n        self.generator = self.helper()\n        self.curr = 0\n        self.all = comb(len(self.characters),self.len)\n        \n    def next(self) -> str:\n        self.curr += 1\n        binary = next(self.generator)\n        return "".join([self.characters[index] for index,val in enumerate(binary) if val == "1"])\n    \n    def hasNext(self) -> bool:\n        return self.curr < self.all\n    \n    def helper(self) -> int:\n        n = len(self.characters)\n        for i in range(2**n-1,-1,-1):\n            b = bin(i)[2:].zfill(n)\n            if str(b).count("1") == self.len:\n                yield b\n```\n\nP.S There are better (faster and optmized) ways to generate binary numbers but this is the most pythonic way I could come up with
[]