Bloomberg Question with Variation
I recently got this quesiton in a phone interview at Bloomberg with a minor variation. The variation was that you won\'t be given size in advance. So, try to so
I recently got this quesiton in a phone interview at Bloomberg with a minor variation. The variation was that you won\'t be given **size** in advance. So, try to solve this question without using variable **n** in the constructor. Here is my implementation.\n\n```\nclass OrderedStream {\n    private Map<Integer, String> buffer;\n    private int currentPointer;\n    public OrderedStream(int n) {\n        currentPointer = 1;\n        buffer = new HashMap<>();\n    }\n    \n    public List<String> insert(int idKey, String value) {\n        List<String> values = new ArrayList<>();\n        if (idKey == currentPointer) {\n            values.add(value);\n            while (buffer.containsKey(++currentPointer))\n                values.add(buffer.remove(currentPointer));\n        } else\n            buffer.put(idKey, value);\n        return values;\n    }\n}\n\n/**\n * Your OrderedStream object will be instantiated and called as such:\n * OrderedStream obj = new OrderedStream(n);\n * List<String> param_1 = obj.insert(idKey,value);\n */\n```
['Java']