Practice Iterator for Combination
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
CombinationIterator(characters,combinationLength) receives sorted distinct lowercase letters. next() returns the next fixed-length combination in lexicographic order. hasNext() reports whether another combination remains. Calls to next are valid. Practice approach: Maintain increasing selected indices. To advance, move the rightmost index that still has room and reset later indices to consecutive successors. This generates combinations in order without permutations or duplicates. Keep exhaustion separate from the current value. Test length one and selecting all characters.
Source: Iterator for Combination on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["CombinationIterator","next","next","hasNext","next","hasNext"] [["acd",2],[],[],[],[],[]]
[null,"ac","ad",true,"cd",false]
The two-letter combinations are ac, ad, and cd in lexical order.
Constraints
Related LeetCode Problems
Practice more problems similar to Iterator for Combination.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.