Java TreeMap And TreeSet
\npublic List<List<String>> displayTable(List<List<String>> orders) {\n        List<List<String>> res = new ArrayList<>();\n        List<String> firstRow = new 
```\npublic List<List<String>> displayTable(List<List<String>> orders) {\n        List<List<String>> res = new ArrayList<>();\n        List<String> firstRow = new ArrayList<>();\n        firstRow.add("Table");\n        TreeSet<String> set = new TreeSet<>();\n        TreeMap<Integer,Map<String,Integer>> map = new TreeMap<>();\n        for (List<String> order : orders) {\n            String dish = order.get(2);\n            set.add(dish);\n            Integer table = Integer.parseInt(order.get(1));\n            map.putIfAbsent(table,new HashMap<>());\n            if(map.get(table).containsKey(dish)) {\n                Map<String,Integer> m = map.get(table);\n                m.put(dish,m.getOrDefault(dish,0)+1);\n            } else {\n                map.get(table).put(dish,1);\n            }\n        }\n\n        firstRow.addAll(set);\n        res.add(firstRow);\n        for (Map.Entry<Integer,Map<String,Integer>> entry : map.entrySet()) {\n            List<String> list = new ArrayList<>();\n            list.add(entry.getKey()+"");\n            Map<String,Integer> m = entry.getValue();\n            for (String dish : set) {\n                if(m.containsKey(dish)) {\n                    list.add(m.get(dish)+"");\n                } else {\n                    list.add("0");\n                }\n            }\n            res.add(list);\n        }\n        return res;\n\n    }\n```
[]