No brainer Java solution using backTracking
The very straightforward backtracking solution.\n\nFirst generate all the subStrings of given length, look at question 77 Combinations to gasp the concept: http
The very straightforward backtracking solution.\n\nFirst generate all the subStrings of given length, look at question 77 Combinations to gasp the concept: https://leetcode.com/problems/combinations/\n\nthen simply iterate thru the list of generated strings.\nruntime would be O(2^n), n being directly proportional to the size of the input string, as we are simulating taking and not taking each character\nspace is bounded by the size of the list we are adding to.\n\n```\nclass CombinationIterator {\n    List<String> list;\n    int posn = 0;\n    \n    public CombinationIterator(String characters, int combinationLength) {\n        list = new ArrayList();\n        backTrack(combinationLength, 0, characters, new ArrayList());\n        \n    }\n    \n    private void backTrack(int k, int index, String str, List<Character> currList) {\n        if (currList.size() == k) {\n            list.add(currList.stream().map(e->e.toString()).collect(Collectors.joining()));\n            return;\n        }\n        \n        for (int i = index; i < str.length(); i++) {\n            currList.add(str.charAt(i));\n            backTrack(k, i+1, str, currList);\n            currList.remove(currList.size()-1);\n        } \n    }\n    \n    public String next() {\n        return (list.get(posn++));\n    }\n    \n    public boolean hasNext() {\n        return list.size() >= posn+1;\n    }\n}\n```
['Backtracking', 'Java']