2 Easy to understand and simple Python3 Solutions using List and Dictionary
Method 1 - using List\n\n\nclass OrderedStream:\n\n    def __init__(self, n: int):\n        self.n = n\n        self.val = [0]*n\n        self.cur = 0\n\n    de
**Method 1 - using List**\n\n```\nclass OrderedStream:\n\n    def __init__(self, n: int):\n        self.n = n\n        self.val = [0]*n\n        self.cur = 0\n\n    def insert(self, idKey: int, value: str) -> List[str]:\n        self.val[idKey-1] = value\n        ans = []\n        for i in range(self.cur,self.n):\n            if self.val[i] == 0:\n                self.cur = i\n                return ans\n            ans.append(self.val[i])\n        return ans\n            \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```\n\nRuntime - 477ms\nMemory Usage - 14.7mb\n\n**Method 2 - using Dictionary**\n\n```\nclass OrderedStream:\n\n    def __init__(self, n: int):\n        self.n = n\n        self.d = {}\n        self.cur = 1\n\n    def insert(self, idKey: int, value: str) -> List[str]:\n        self.d[idKey] = value\n        ans = []\n        for i in range(self.cur,self.n+1):\n            if i not in self.d:\n                self.cur = i\n                return ans\n            ans.append(self.d[i])\n        return ans\n            \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```\n\nRuntime - 228ms\nMemory Usage - 14.7mb\n\nFor solutions to other LeetCode problems that I have solved, you can check my github repository :\nhttps://github.com/harshitpoddar09/LeetCode-Solutions\n\nPlease upvote if you found this useful so that others can get help as well!\n
[]