Full Use of DataStructures
\r\nclass Solution {\r\n    public List<List<String>> displayTable(List<List<String>> orders) {\r\n      Map<Integer,Map<String,Integer>>map=new TreeMap<>();\r\
```\r\nclass Solution {\r\n    public List<List<String>> displayTable(List<List<String>> orders) {\r\n      Map<Integer,Map<String,Integer>>map=new TreeMap<>();\r\n      Set<String>set=new TreeSet<>();\r\n      for(List<String>list:orders){\r\n        int n=Integer.parseInt(list.get(1));\r\n        String dish=list.get(2);\r\n        set.add(dish);\r\n        map.putIfAbsent(n,new HashMap<>());\r\n        if(map.get(n).containsKey(dish)){\r\n            Map<String,Integer>row=map.get(n);\r\n            row.put(dish,row.getOrDefault(dish,0)+1);\r\n        }\r\n        else{\r\n            map.get(n).put(dish,1);\r\n        }\r\n      }\r\n      List<List<String>>ans=new ArrayList();\r\n      List<String>headings=new ArrayList();\r\n      headings.add("Table");\r\n      headings.addAll(set);\r\n      ans.add(headings);\r\n      for(Map.Entry<Integer,Map<String,Integer>>m:map.entrySet()){\r\n          List<String>row=new ArrayList<>();\r\n          row.add(m.getKey()+"");\r\n          Map<String,Integer>mp=m.getValue();\r\n          for(String s:set){\r\n              if(mp.containsKey(s)){\r\n                  row.add(mp.get(s)+"");\r\n              }\r\n              else{\r\n                  row.add(0+"");\r\n              }\r\n          }\r\n          ans.add(row);\r\n      }\r\n      return ans; \r\n    }\r\n}\r\n```
['Java']