JavaScript Hash map, O(n log n)
Time Complexity: O(n log n)\n- Space Complexity: O(n)\n\nJavaScript\n/**\n * @param {string[][]} orders\n * @return {string[][]}\n */\nvar displayTable = functi
- Time Complexity: O(n log n)\n- Space Complexity: O(n)\n\n```JavaScript\n/**\n * @param {string[][]} orders\n * @return {string[][]}\n */\nvar displayTable = function(orders) {\n    const memo = new Map(), items = new Set();\n    for ([_, t, item] of orders) {\n        if (!memo.has(t)) {\n            memo.set(t, new Map());\n        }\n        memo.get(t).has(item) ? memo.get(t).get(item)[0]++ : memo.get(t).set(item, [1]);\n        items.add(item);\n    }\n    const table = [[...items].sort()];\n    for (key of [...memo.keys()].sort((a,b) => 1 * a > 1 * b ? 1 : -1)) {\n        const row = [key];\n        for (x of table[0]) {\n            row.push(memo.get(key).has(x) ? memo.get(key).get(x)[0] + \'\' : \'0\');\n        }\n        table.push(row)\n    }\n    table[0].unshift(\'Table\');\n    return table;\n};\n```
['JavaScript']