Practice Design an Ordered Stream
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
OrderedStream(n) receives unique IDs from 1 through n out of order. insert(idKey,value) stores a pair and returns the largest consecutive chunk that can now be emitted in increasing ID order, starting after the last emitted value. Missing next IDs produce an empty chunk. Practice approach: Keep an array indexed by ID and a pointer starting at one. After insertion, advance and emit while the pointer identifies a stored value. Each entry is emitted once, giving O(n) total emission work and O(n) storage. Do not re-emit earlier chunks.
Source: Design an Ordered Stream on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["OrderedStream","insert","insert","insert"] [[3],[2,"bravo"],[1,"alpha"],[3,"cider"]]
[null,[],["alpha","bravo"],["cider"]]
The first pair waits for ID 1; receiving ID 1 releases both pending entries.
Constraints
Related LeetCode Problems
Practice more problems similar to Design an Ordered Stream.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.