Given&nbsp;the array orders, which represents the orders that customers have done in a restaurant. More specifically&nbsp;orders[i]=[customerNamei,tableNumberi,foodItemi] where customerNamei is the name of the customer, tableNumberi&nbsp;is the table customer sit at, and foodItemi&nbsp;is the item customer orders.

Return the restaurant's “display table”. The “display table” is a table whose row entries denote how many of each food item each table ordered. The first column is the table number and the remaining columns correspond to each food item in alphabetical order. The first row should be a header whose first column is “Table”, followed by the names of the food items. Note that the customer names are not part of the table. Additionally, the rows should be sorted in numerically increasing order.

&nbsp;
Example 1:

Input: orders = [["David","3","Ceviche"],["Corina","10","Beef Burrito"],["David","3","Fried Chicken"],["Carla","5","Water"],["Carla","5","Ceviche"],["Rous","3","Ceviche"]]
Output: [["Table","Beef Burrito","Ceviche","Fried Chicken","Water"],["3","0","2","1","0"],["5","0","1","0","1"],["10","1","0","0","0"]] 
Explanation:
The displaying table looks like:
Table,Beef Burrito,Ceviche,Fried Chicken,Water
3    ,0           ,2      ,1            ,0
5    ,0           ,1      ,0            ,1
10   ,1           ,0      ,0            ,0
For the table 3: David orders "Ceviche" and "Fried Chicken", and Rous orders "Ceviche".
For the table 5: Carla orders "Water" and "Ceviche".
For the table 10: Corina orders "Beef Burrito". 


Example 2:

Input: orders = [["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]]
Output: [["Table","Canadian Waffles","Fried Chicken"],["1","2","0"],["12","0","3"]] 
Explanation: 
For the table 1: Adam and Brianna order "Canadian Waffles".
For the table 12: James, Ratesh and Amadeus order "Fried Chicken".


Example 3:

Input: orders = [["Laura","2","Bean Burrito"],["Jhon","2","Beef Burrito"],["Melissa","2","Soda"]]
Output: [["Table","Bean Burrito","Beef Burrito","Soda"],["2","1","1","1"]]


&nbsp;
Constraints:


	1 &lt;=&nbsp;orders.length &lt;= 5 * 10^4
	orders[i].length == 3
	1 &lt;= customerNamei.length, foodItemi.length &lt;= 20
	customerNamei and foodItemi consist of lowercase and uppercase English letters and the space character.
	tableNumberi&nbsp;is a valid integer between 1 and 500.

class Solution:
    def displayTable(self, orders: List[List[str]]) -> List[List[str]]:
        column = ['Table']
        dish = []
        table_dict = {}
        for order_row in orders : 
            if order_row[-1] not in dish :
                dish.append(order_row[-1])
        
        for order_row in orders :
            if order_row[1] not in table_dict.keys() :
                table_dict[order_row[1]] = {}
                for food in dish : 
                    table_dict[order_row[1]][food] = 0 
                table_dict[order_row[1]][order_row[-1]] += 1
            else : 
               table_dict[order_row[1]][order_row[-1]] += 1 
        
        dish.sort()
        column = column + dish 
        ans = [column]
        table = []
        childDict = {}
        for key in sorted(table_dict.keys()) : 
            table.append(int(key))
            childDict[key] = []
            for value in column : 
                if value != 'Table' :
                    childDict[key].append(str(table_dict[key][value]))
        table.sort()
        output = [ans[0]]
        for table_num in table : 
            childList = [str(table_num)]
            output.append(childList + childDict[str(table_num)])
        return output 
class Solution {
    public List<List<String>> displayTable(List<List<String>> orders) {
        List<List<String>> ans = new ArrayList<>();
        List<String> head = new ArrayList<>();
        head.add("Table");
        Map<Integer, Map<String,Integer>> map = new TreeMap<>();
        for(List<String> s: orders){
            if(!head.contains(s.get(2))) head.add(s.get(2));
            int tbl = Integer.parseInt(s.get(1));
            map.putIfAbsent(tbl, new TreeMap<>());
            if(map.get(tbl).containsKey(s.get(2))){
                Map<String, Integer> m = map.get(tbl);
                m.put(s.get(2), m.getOrDefault(s.get(2), 0)+1);
            }else{
                map.get(tbl).put(s.get(2), 1);
            }
        }
        String[] arr = head.toArray(new String[0]);
        Arrays.sort(arr, 1, head.size());
        head = Arrays.asList(arr);
        ans.add(head);

        for(Map.Entry<Integer, Map<String, Integer>> entry: map.entrySet()){
            List<String> l = new ArrayList<>();
            l.add(entry.getKey() + "");
            Map<String,Integer> m = entry.getValue();
            for(int i=1; i<arr.length; i++){
                if(m.containsKey(arr[i])){
                    l.add(m.get(arr[i])+"");
                }else{
                    l.add("0");
                }
            }
            ans.add(l);
        }
        System.out.print(map);
        return ans;
    }
}
class Solution {

public:

    vector<vector<string>> displayTable(vector<vector<string>>& orders) {



    vector<vector<string>>ans;

    map<int,map<string,int>>m;

    set<string>s; //Sets are useful as they dont contain duplicates as well arranges the strings in order.

    for(auto row:orders)

    {

        s.insert(row[2]);

        m[stoi(row[1])][row[2]]++;

    }



    vector<string>dem;

    dem.push_back("Table");

    for(auto a:s)

    {

        dem.push_back(a);

    }//For the  first row only



    ans.push_back(dem);

    for(auto it:m)

    {

        vector<string>row;

        row.push_back(to_string(it.first));

        auto dummy=it.second;

        for(auto st:s)//we use set here as it has food names stored in asc order.

        {

            row.push_back(to_string(dummy[st]));//we access the number of orders.

        }



        ans.push_back(row);



    }



    return ans;





    }

};
var displayTable = function(orders) {
    var mapOrders = {};
    var tables = [];
    var dishes = [];
    for(var i=0;i<orders.length;i++){
        //if entry of table doesn't exist in mapOrders
        if(mapOrders[orders[i][1]] == undefined){
            //conver table number to integer
            var tableNo = Number(orders[i][1])
            mapOrders[tableNo] = {}
            mapOrders[tableNo][orders[i][2]] = 1;
            //if table number doesn't exist in table array, push it in the table array
            if(!tables.includes(tableNo)){tables.push(tableNo)}
            //if dish doesn't exist in dishes array, push it in the dishes array
            if(!dishes.includes(orders[i][2])){dishes.push(orders[i][2])}
        }else{
            //if entry of table exists in mapOrders
            //conver table number to integer
            var tableNo = Number(orders[i][1])
            var entry = mapOrders[tableNo];
            //check if entry of dish exists in for that table in mapOrders
            if(entry[orders[i][2]] == undefined){
                entry[orders[i][2]] = 1;
            }else{
                entry[orders[i][2]] = entry[orders[i][2]] + 1;
            }
            //if dish doesn't exist in dishes array, push it in the dishes array
            if(!dishes.includes(orders[i][2])){dishes.push(orders[i][2])}
        }
    }
    //sort tables and dishes
    tables.sort(function(a,b){return a-b});
    dishes.sort();
    //append word "Table" with all dish names om row[0] of result
    var res = [["Table"]];
    for(var i=0;i<dishes.length;i++){
        res[0].push(dishes[i]);
    }
    // read through map based on sorted table order
    for(var i=0;i<tables.length;i++){
        // append result in a temp array
        var tmp = [];
        //converting number to string using ""+
        tmp.push(""+tables[i]);
        for(var j=0;j<dishes.length;j++){
            if(mapOrders[tables[i]][dishes[j]]==undefined){
                //if dish doesn't exist against that table then append "0" to the result for that dish
                tmp.push(""+0);
            }else{
                //if dish exists against that table then append value in mapOrders for that pair of (table,dish) to the result
                tmp.push(""+mapOrders[tables[i]][dishes[j]]);
            }
        }
        //append the temp array in result
        res.push(tmp);
    }
    return res;
};
Display Table of Food Orders in a Restaurant