Latest Python solution explained for newly updated description: Faster than 90%
The idea behind this problem is simple but the description is confusing.\nSo let me explain a bit.\n\nBasically , we need to store every incoming value at the g
The idea behind this problem is simple but the description is confusing.\nSo let me explain a bit.\n\nBasically , we need to store every incoming value at the given index. And \nwith every incoming index, we have to check\n\n* If the current index is less than the incoming index, the we have to return\n    an empty list\n\n* Else , we have to return an sliced list from the incoming index to the first index\n    where there is no insertion till yet.\n\nSolution:\n* Initialize a list of size n with None\n* Maintain the current index with self.ptr\n* For every insert call, with idKey, value \n    * Assign the list[idKey-1] to the value # Since array is 0-index reduce 1\n    * Check if the current index is less than incoming index(idKey-1) and return []\n    * Else return sliced list from incoming index(idKey-1) till we do not encounter  None.\n\n\n```\nclass OrderedStream:\n\n    def __init__(self, n):\n        self.stream = [None]*n\n        self.ptr = 0\n\n    def insert(self, idKey, value):\n        idKey -= 1\n        self.stream[idKey] = value\n        if self.ptr < idKey:\n            return []\n        else:\n            while self.ptr < len(self.stream) and self.stream[self.ptr] is not None:\n                self.ptr += 1\n            return self.stream[idKey:self.ptr]\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```
['Python', 'Python3']