Python :: Priority Queue
\nclass OrderedStream:\n\n    def __init__(self, n: int):\n        self.n = n\n        self.ans = []\n        \n        self.counter = 1\n\n    def insert(self,
```\nclass OrderedStream:\n\n    def __init__(self, n: int):\n        self.n = n\n        self.ans = []\n        \n        self.counter = 1\n\n    def insert(self, idKey: int, value: str) -> List[str]:\n        ans = []\n        heapq.heappush(self.ans, (idKey, value))\n        \n        x = heapq.heappop(self.ans) if self.ans else None\n        while x and self.counter == x[0]:\n            ans.append(x[1])\n            x = heapq.heappop(self.ans) if self.ans else None\n            self.counter += 1\n        if x:\n            heapq.heappush(self.ans, x)\n        \n        return ans\n\n\n# Your OrderedStream object will be instantiated and called as such:\n# obj = OrderedStream(n)\n# param_1 = obj.insert(idKey,value)\n```
[]