#315 Iterator for Nested String Iterators

Companies:
Sberbank
Themes:
JavaCollections & GenericsPractice

Implement the following class:

Java
public class SuperIterator implements Iterator<String> {
    public SuperIterator(Object... iterators) {
        ...
    }
}

The constructor arguments may be a String, an Iterator<String>, or an Iterator<Iterator<String>>, generalized to iterators of any nesting depth. Example:

Java
var it0 = Collections.<String>emptyList().iterator();
var it1 = Arrays.asList("1", "2", "3").iterator();
String it2 = "4";
var it3 = Arrays.asList(
    Arrays.asList("5").iterator(),
    Arrays.asList("6", "7").iterator()).iterator();
var it = new SuperIterator(it1, it2, it0, it3);
while (it.hasNext()) {
    System.out.println(it.next());
}

It must print 1, 2, 3, 4, 5, 6, 7, each on a new line.

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in