JAVA Solution
\n\n# Complexity\n- Time complexity:\nthe time complexity of the code is dominated by the insert() method, which is O(k) where k is the number of elements inser
\n\n# Complexity\n- Time complexity:\nthe time complexity of the code is dominated by the insert() method, which is O(k) where k is the number of elements inserted so far.\n\n- Space complexity:\nThe space complexity of this code is O(n), where n is the number of elements that the stream can hold.\n\n# Code\n```\nclass OrderedStream {\n    private String[] data;\n    private int ptr;\n\n    public OrderedStream(int n) {\n        data = new String[n + 1];\n        ptr = 1;\n    }\n\n    public String[] insert(int idKey, String value) {\n        data[idKey] = value;\n        List<String> res = new ArrayList<>();\n        for (int i = ptr; i < data.length; i++) {\n            if (data[i] != null) {\n                res.add(data[i]);\n            } else {\n                ptr = i;\n                break;\n            }\n        }\n        return res.toArray(new String[0]);\n    }\n}\n\n```
['Java']