Beats 80% runtime, 90% memory
\r\n\r\n# Code\r\n\r\nclass Solution:\r\n    def displayTable(self, orders: List[List[str]]) -> List[List[str]]:\r\n        header = ["Table"]\r\n        map_ta
\r\n\r\n# Code\r\n```\r\nclass Solution:\r\n    def displayTable(self, orders: List[List[str]]) -> List[List[str]]:\r\n        header = ["Table"]\r\n        map_table = {}\r\n        item_set = set()\r\n\r\n        for order in orders:\r\n            item = order[2]\r\n            \r\n            item_set.add(item)\r\n\r\n            table_no = order[1]\r\n            if not (table_no in map_table):\r\n                map_table[table_no] = {}\r\n\r\n            if item in map_table[table_no]:\r\n                map_table[table_no][item] += 1\r\n            else:\r\n                map_table[table_no][item] = 1\r\n    \r\n        result = [header]\r\n        sorted_item = sorted(item_set)\r\n\r\n        for item in sorted_item:\r\n            header.append(item)\r\n\r\n        for k, v in sorted(map_table.items(), key=lambda item: int(item[0])):\r\n            row = [k]\r\n            for item in sorted_item:\r\n                row.append(str(v[item] if item in v else "0"))\r\n            result.append(row)\r\n\r\n        return result\r\n```
['Python3']