Design an Ordered Stream
Too many downvotes. Bad problem description. Do not waste time on this one.
Here is a Python solution for the problem. This solution uses an array to store the values, and an integer to keep track of the current position. When an insertion is made, it checks if the inserted key is at the current position, if so, it adds all the continuous values to the result until it encounters an empty position.
|
|
In the insert
method, we first insert the value at the correct position. Then, we check if the current position of the pointer is equal to the inserted idKey. If it is, we add all the continuous values in the stream to the result, updating the pointer to the new position where the next value is expected.
This way, each time insert
is called, it returns the largest possible chunk of currently inserted values that appear next in order.