Java Simple Solution || Explained
^^ Upvote if you like the solution :)\n```\nclass Solution {\n    public List> displayTable(List> orders) {\n\t\t//the map below will store tables with food nam
^^ Upvote if you like the solution :)\n```\nclass Solution {\n    public List<List<String>> displayTable(List<List<String>> orders) {\n\t\t//the map below will store tables with food names and their overall quantity in all orders\n        //table -> (food -> quantity)\n        Map<Integer, Map<String, Integer>> map = new TreeMap<>();\n\t\t//this set below is needed for unique food names to compose the final table with all names\n\t\t//appeared in the given list of orders\n        Set<String> foods = new TreeSet<>();\n        for (int i = 0; i < orders.size(); i++) {\n            List<String> order = orders.get(i);\n            Integer table = Integer.parseInt(order.get(1));\n            String food = order.get(2);\n            if (map.containsKey(table)) {\n                Map<String, Integer> foodsMap = map.get(table);\n                if (foodsMap.containsKey(food)) {\n                    foodsMap.put(food, foodsMap.get(food) + 1);\n                } else {\n                    foods.add(food);\n                    foodsMap.put(food, 1);\n                }\n            } else {\n                foods.add(food);\n                Map<String, Integer> newFoodsMap = new TreeMap<>();\n                newFoodsMap.put(food, 1);\n                map.put(table, newFoodsMap);\n            }\n        }\n\t\t//composing the final table\n        List<List<String>> list = new ArrayList<>();\n        List<String> header = new ArrayList<>();\n        header.add("Table");\n        for (String foodName : foods) {\n            header.add(foodName);\n        }\n        list.add(header);\n        for (Integer tableNum : map.keySet()) {\n            List<String> tableOrders = new ArrayList<>();\n            tableOrders.add(tableNum + "");\n            Map<String, Integer> table = map.get(tableNum);\n            for (String foodName : foods) {\n                if (table.containsKey(foodName)) {\n                    tableOrders.add(table.get(foodName) + "");\n                } else {\n                    tableOrders.add("0");\n                }\n            }\n            list.add(tableOrders);\n        }\n        return list;\n    }\n}
[]