C++ | Clean | Easy | Faster than 100% | With Proper Comments
\n//Main concept of the problem\n\n//1. First we try to find all unique tables and food items in ascending order.\n//which can easily be done by set all the dup
```\n//Main concept of the problem\n\n//1. First we try to find all unique tables and food items in ascending order.\n//which can easily be done by set all the duplicate values will automatically will be removed.\n\n//2.From these two set we can make 2 maps which will give us the index of tableNumber and index of foodItem in sorted set. \n// (ie that indexes will match with the index in resulting vector)\n\n//3.Now just traverse through orders and find the index of tableNumber(row for the resulting vector) \n// and foodItem(col for the resulting vector) from the above maps.\n\nclass Solution {\npublic:\n    vector<vector<string>> displayTable(vector<vector<string>>& orders) {\n\n        set<int> tableNums;\n        set<string> foodItems;\n\n        //first get all the unique tableNumber and foodItems\n        for(int i=0;i<orders.size();i++)\n        {\n            tableNums.insert(stoi(orders[i][1]));\n            foodItems.insert(orders[i][2]);\n        }\n\n        vector<vector<string>> res(tableNums.size()+1,vector<string>(foodItems.size()+1,"0"));\n        \n        unordered_map<string,int> fmap;\n        unordered_map<int,int> tmap;\n        res[0][0]="Table";\n\n        int counter=1;\n        for(auto i:foodItems) {\n            fmap[i] = counter;\n            res[0][counter]=i;\n            counter++;\n        }\n        counter=1;\n        for(auto i:tableNums) {\n            tmap[i] = counter;\n            res[counter][0]=to_string(i);\n            counter++;\n        }\n        int t,f;\n        for(int i=0;i<orders.size();i++)\n        {\n            t=tmap[stoi(orders[i][1])];\n            f=fmap[orders[i][2]];\n            res[t][f]=to_string(stoi(res[t][f])+1);\n        }\n        return res;\n    }\n};```\n\nI tried to explain to best of my abilities but this question is hard to explain. Cheers . Happy Coding.
[]