super clear  🐍 illustrated explanation
<-- please vote\n\n\n\n\nclass OrderedStream:\n\n    def init(self, n: int):\n        """ O(N)S"""\n        self.arr = [None] * (n + 1)\n        self.ptr = 1\n\
<-- please vote\n\n![image](https://assets.leetcode.com/users/images/71bcfb09-61a6-46cb-9c06-189364872183_1652705869.6314733.png)\n\n\nclass OrderedStream:\n\n    def __init__(self, n: int):\n        """ O(N)S"""\n        self.arr = [None] * (n + 1)\n        self.ptr = 1\n\n    def insert(self, idKey: int, value: str) -> List[str]:\n        self.arr[idKey] = value\n        while self.ptr < len(self.arr) and self.arr[self.ptr] is not None:\n            self.ptr += 1\n        return self.arr[idKey:self.ptr]
[]