Java | 2 different solution | With detailed explanation
\nEXPLANATION:-\n-> In this solution, first generate all combinations\n-> use a pointer to get the combination\n-> if pointer reads all the combinations, then h
```\nEXPLANATION:-\n-> In this solution, first generate all combinations\n-> use a pointer to get the combination\n-> if pointer reads all the combinations, then hasNext method return false;\n\nSolution1:-\nclass CombinationIterator {\n    ArrayList<String> comb;\n    int pointer, cLen;\n    public CombinationIterator(String characters, int combinationLength) {\n        this.comb = new ArrayList<>();\n        this.pointer = 0;\n        this.cLen = combinationLength;\n        this.combinations(characters, 0, "");\n    }\n    public void combinations(String s, int index, String com){\n        if(com.length() == this.cLen){\n            this.comb.add(com);\n            return ;\n        }\n        if(index >= s.length()) return ;\n        for(int i = index; i < s.length(); i++)\n            combinations(s, i + 1, com + String.valueOf(s.charAt(i)));\n    }\n    public String next() {\n        return this.comb.get(this.pointer++);\n    }\n    \n    public boolean hasNext() {\n        return this.pointer < this.comb.size();\n    }\n}\n\n-> In this solution, we will maintain list of numbers in which \n     each number has (number of 1s in its binary number == combinationLength).\n-> Now, in next function, we will get each number and generate combination\n     Ex:-   S = abc and len = 2\n\t then we have list = [6, 5, 3]\n\t Now, how can we generate string from number?\n\t \n\t Here, each bit in the number represents a character in S\n\t 1st call of next:-\n\t So, num = 6 -> 110(Binary)\n\t S = a b c\n\t N = 1 1 0 (Simply add all the characters which have 1 as corresponding bit)\n\t Generated combination is ab.\n\t \n\t 2nd call of next:-\n\t So, num = 5 -> 101\n\t S = a b c\n\t N = 1 0 1\n\t Generated combination is ac (since bits at  positions of a and c are 1).\n\t \n\t 3rd call of next:-\n\t So, num = 3 -> 011\n\t S = a b c\n\t N = 0 1 1\n\t Generated combination is bc.\n\t \n\t Now, we are done with all the combinations of length 2.\n\t Now, any call hasNext returns false since there are no numbers to read.\n\nIF YOU UNDERSTAND THESE SOLUTIONS, UPVOTE. \nIF YOU HAVE ANY DOUBTS, FEEL FREE TO ASK.\n\nSolution2 :-\nclass CombinationIterator {\n    ArrayList<Integer> comb;\n    int pointer;\n    String s;\n    public CombinationIterator(String characters, int combinationLength) {\n        this.comb = new ArrayList<>();\n        this.pointer = 0;\n        this.s = characters;\n        int n = characters.length();\n        for(int i = (1 << n) - 1; i > 0; i--)\n            if(countBits(i) == combinationLength) comb.add(i);\n    }\n    public int countBits(int n){\n        int count = 0;\n        while(n > 0){\n            n &= (n - 1);\n            count++;\n        }\n        return count;\n    }\n    public String next() {\n        StringBuilder ans = new StringBuilder();\n        int num = this.comb.get(this.pointer++);\n        int index = s.length() - 1;\n        while(num > 0){\n            if((num & 1) > 0) ans.insert(0, s.charAt(index));\n            num >>= 1;\n            index--;\n        }\n        return ans.toString();\n    }\n    \n    public boolean hasNext() {\n        return this.pointer < this.comb.size();\n    }\n}\n\n```\n\nI have started a series on solid principles and design patterns. If anyone is interested, please check [it](https://medium.com/@bhanu150138/mastering-solid-principles-and-design-patterns-a-blog-series-for-writing-clean-scalable-code-aae3809310db) out.
['String', 'Backtracking', 'Design', 'Iterator']