← 返回 bloomberg 的题目列表Design an Ordered Stream
类型:online_judge
Design a data structure OrderedStream that receives n unique pairs (id, value) where id is in [1, n].
The stream maintains a pointer ptr starting at 1. After inserting (id, value), if there is a consecutive run of inserted ids starting from ptr (i.e., ptr, ptr+1, ..., k), return the corresponding values in order and move ptr to k+1. Otherwise return an empty list.
Implement:
OrderedStream(n)
insert(id, value) -> List[str]
Constraints: 1 <= n <= 1000, value is a string.
Example
Input
n=5
insert(3,"ccccc")
Output
[]