Does leetcode have this question???
Problem statement:
You're given 2 integer iterator objects of type Stream
//guaranteed to give non decreasing output for getNext
interface Stream{
int getNext();
boolean hasNext();
}
Given Stream s1 and s2, design a datastructure (uber iterator) that takes these streams and outputs
class UberIterator{
Stream s1, s2;
int getNext(){
//write code
}
boolean hasNext(){
//write code
}
}
Sample output. Lets say s1 and s2 have the following getNext streams.
s1: 1, 3, 7, 11, 23
s2: 2, 5 , 7, 10, 14
Required Output of UberIterator (getNext): 1, 2, 3, 5, 7, 7, 10, 11, 14, 23
Follow up: How to generalize with n stream objects???