[Java] 9ms beats 100%. No bits, no queues, no pregeneration
The idea is to store array of indexes of letters in original string and update them when next() is called.\nFor example: string is characters="abcd" and combina
The idea is to store array of indexes of letters in original string and update them when ```next()``` is called.\nFor example: string is ```characters="abcd"``` and ```combinationLength=3```\n1. ```abc``` and index array will be ```[0, 1, 2]```\n2. When ```next()``` is called we increase last value by 1: ```abd``` and ```[0, 1, 3]```\n3. With next call our last value will be more than maximum. Maximum is different for each index. For last index it is equals to the length of the string minus 1 (3), for penultimate it is length of the string minus 2 (2) and so on. When maximum is reached we increace previois index by 1 and curren index will be new previous + 1 (because we iterating only for combinations and not all premutations). So now we will have ```acd``` and ```[0, 2, 3]```\n4. And so on\n\n```hasNext()``` returns true until first index reaches it\'s maximum (in this case it is 1 and whole array will be ```[1, 2, 3]```)\n\nI initiate index array with last index 1 less than it should be so we could first update and then build resulting string/\n\n```java\nclass CombinationIterator {\n    \n    private final char[] chars;\n    private final int[] ids;\n\n    public CombinationIterator(String characters, int combinationLength) {\n        chars = characters.toCharArray();\n        ids = new int[combinationLength];\n        for(int i = 0; i < combinationLength; i++) {\n            ids[i] = i;\n        }\n        ids[combinationLength - 1]--;\n    }\n    \n    public String next() {\n        update(ids.length - 1);\n        StringBuilder sb = new StringBuilder();\n        for(int i = 0; i < ids.length; i++) {\n            sb.append(chars[ids[i]]);\n        }\n        return sb.toString();\n    }\n    \n    private void update(int idx) {\n        if (idx < 0 || idx >= ids.length) return;\n        ids[idx]++;\n        if (ids[idx] >= chars.length - (ids.length - 1 - idx)) {\n            update(idx - 1);\n            ids[idx] = ids[idx - 1] + 1;\n        }\n    }\n    \n    public boolean hasNext() {\n        return ids[0] != chars.length - ids.length;\n    }\n}\n```
[]