JAVA SOLUTION USING HASHMAP AND TREESET
class Solution {\n    public List> displayTable(List> orders) {\n\t\n        List> table = new ArrayList<>();\n        \n        HashMap> map = new HashMap<>();
class Solution {\n    public List<List<String>> displayTable(List<List<String>> orders) {\n\t\n        List<List<String>> table = new ArrayList<>();\n        \n        HashMap<String,HashMap<Integer,Integer>> map = new HashMap<>();\n        \n        TreeSet<Integer> tables = new TreeSet<>();\n        \n        TreeSet<String> items = new TreeSet<>();\n        \n        for(List<String> order:orders)\n        {\n            int tableNumber = Integer.parseInt(order.get(1));\n            String item = order.get(2);\n            \n            items.add(item);\n            \n            tables.add(tableNumber);\n            \n            if(map.containsKey(item))\n            {\n                HashMap<Integer,Integer> m = map.get(item);\n                m.put(tableNumber,m.getOrDefault(tableNumber,0)+1);\n                map.put(item,m);\n            }\n            else\n            {\n                HashMap<Integer,Integer> m = new HashMap<>();\n                m.put(tableNumber,1);\n                map.put(item,m);\n            }\n        }\n        \n        List<String> firstRow = new ArrayList<>();\n        \n        firstRow.add("Table");\n        \n        for(String s:items)\n        {\n            firstRow.add(s);\n        }\n        \n        table.add(firstRow);\n        \n        items = null;\n        \n        for(Integer i:tables)\n        {\n            List<String> row = new ArrayList<>();\n            \n            row.add(String.valueOf(i));\n            \n            int m = firstRow.size();\n            \n            for(int j=1;j<m;j++)\n            {\n                String item = firstRow.get(j);\n                \n                if(map.get(item).containsKey(i))\n                {\n                    int number = map.get(item).get(i);\n                    \n                    row.add(String.valueOf(number));\n                }\n                else{\n                    row.add("0");\n                }\n            }\n            \n            table.add(row);\n        }\n        \n        return table;\n        \n    }\n}
['Tree', 'Ordered Set', 'Java']