Shortest & Easiest Brute - Force Approach with Detailed Explanation 💡 ✅
1. Understanding the Problem 🧐You have a restaurant 🍽️ where customers place orders. The goal is to create a table 📊 that shows how many times each food item wa
# 1. Understanding the Problem 🧐
**You have a restaurant 🍽️ where customers place orders. The goal is to create a table 📊 that shows how many times each food item was ordered at each table. The output must be organized by table number 🏷️, and the columns should be sorted by food item in alphabetical order 🔠.**
# 2. The Plan 💡
To approach this problem, we’ll:
* Collect the data 🗂️ from the orders.
* Track how many times each food is ordered at each table 📋.
* Sort the food items and table numbers 🔢.
* Display the table in the required format 🖨️.
# 3. Step-by-Step Breakdown 📅
**Step 1: Storing the Orders 📦**

We’ll store the orders using a map 🗺️:
* Outer map: The key is the table number (int), and the value is another map.
* Inner map: The key is the food item (string), and the value is the count of how many times the food is ordered at that table 🍔🍕

Also, we’ll use a set to store the food items in alphabetical order 🔠.

**📝 Example:**

**map<int, map<string, int>> tableOrders; // Store food orders by table
set<string> foodItems; // Store unique food items**

**Step 2: Processing Each Order 🔄**

We loop through each order 🌀:
* Extract table number 🏷️ and food item 🍝 from the order.
* Increment the count for the corresponding table and food item in our map.
* Add the food item to the set to keep track of all food items 🍽️.

**🔍 Example:**

**tableOrders[tableNumber][foodItem]++; // Increase the count for this food at the table
foodItems.insert(foodItem); // Add food item to the set**

**Step 3: Create the Header Row 📑**

The header row will have:
* The word "Table" in the first column ✨.
* All the food items sorted alphabetically in the remaining columns 🥗🍕.

**👨‍🍳 Example:**

**vector<string> header = {"Table"}; // First column is "Table"
for (auto& food : foodItems) {
    header.push_back(food); // Add each food item to the header
}**

**Step 4: Creating the Table Rows 📊**

For each table:
* The first column will have the table number 🏷️.
* The remaining columns will show how many times each food item was ordered at this table. If a table didn’t order a specific food, we show 0 📉.

**👀 Example:**

**for (auto& table : tableOrders) {
    vector<string> row = {to_string(table.first)}; // First column is table number
    for (auto& food : foodItems) {
        row.push_back(to_string(table.second.count(food) ? table.second.at(food) : 0)); // Add food count
    }
}**

**Step 5: Print the Table 🖨️**

Finally, we’ll print the header and the table rows! 📃

**for (auto& row : result) {
    for (auto& cell : row) {
        cout << cell << " "; // Print each cell
    }
    cout << endl; // New line after each row
}**
# 5. Final Output 🎉
The final table will look like this:

**Table Ceviche Fried Chicken Burger Fries
2 1 1 0 0
3 1 1 0 0
5 0 0 1 1**
# Summary 🎯
* Data Structures: We used a map for counting orders and a set for sorting food items 🍲.
* Sorting: Food items were sorted alphabetically using the set 🔠.
* Output: We printed the table in the desired format 🖨️.

# Code
```cpp [My Code 🧑‍💻]
class Solution {
public:
    vector<vector<string>> displayTable(vector<vector<string>>& orders) {
        map<int, map<string, int>> tableOrders;
        set<string> foodItems;
        for (auto& order : orders) {
            int tableNumber = stoi(order[1]);
            string foodItem = order[2];
            tableOrders[tableNumber][foodItem]++;
            foodItems.insert(foodItem);
        }
        vector<string> header = {"Table"};
        for (auto& food : foodItems)
            header.push_back(food);
        vector<vector<string>> result;
        result.push_back(header);
        for (auto& table : tableOrders) {
            vector<string> row = {to_string(table.first)};
            for (auto& food : foodItems) {
                row.push_back(to_string(table.second.count(food) ? table.second.at(food) : 0));
            }
            result.push_back(row);
        }
        return result;
    }
};
```
['C++']