[JS] O(n) solution using hashmap
\nclass OrderedStream {\n    constructor(n) {\n        this.map = new Map();\n        this.key = 1;\n    }\n    insert(idKey, value) {\n        this.map.set(idK
```\nclass OrderedStream {\n    constructor(n) {\n        this.map = new Map();\n        this.key = 1;\n    }\n    insert(idKey, value) {\n        this.map.set(idKey, value);\t\t// add the key-value to the map\n        const result = [];\n\t\t// until able to find the key in the map, add it to the resultant chunk\n\t\t// each time the next greater key is found, it will start the result from that key value\n        while(this.map.has(this.key)) { // O(n)\n            result.push(this.map.get(this.key));\n            ++this.key;\n        }\n        return result;\n    }\n}\n```\nTime Complexity = O(n)\nSpace Complexity = O(n)
['JavaScript']