Highly intuitive and simple solution
IntuitionApproachHashMap of HashMap.
table -> foodCounter
will look like
{
3: {food1: 2, food2: 3},
5: {food1: 10, food4: 5},
1: {food9: 3}
}Complexity
Time com
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
HashMap of HashMap. 
table -> foodCounter
will look like 
{
3: {food1: 2, food2: 3},
5: {food1: 10, food4: 5},
1: {food9: 3}
}

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public List<List<String>> displayTable(List<List<String>> orders) {
        HashMap<Integer, HashMap<String, Integer>> m = new HashMap<>();
        Set<String> foods = new TreeSet<>();
        Set<Integer> tables = new TreeSet<>();
        for(int i=0; i<orders.size(); i++) {
            int table = Integer.parseInt(orders.get(i).get(1));
            tables.add(table);
            String food = orders.get(i).get(2);
            foods.add(food);
            if(!m.containsKey(table)) {
                HashMap<String, Integer> foodCounter = new HashMap<>();
                foodCounter.put(food, 1);
                m.put(table, foodCounter);
            }
            else {
                HashMap<String, Integer> foodCounter = m.get(table);
                foodCounter.put(food, foodCounter.getOrDefault(food, 0)+1);
                m.put(table, foodCounter);
            }
        }
        List<List<String>> ans = new ArrayList<>();
        List<String> row1 = new ArrayList<>();
        row1.add("Table");
        for(String i:foods) {
            row1.add(i);
        }
        ans.add(row1);
        for(int table:tables) {
            List<String> curRow = new ArrayList<>();
            curRow.add(table+"");
            HashMap<String, Integer> foodCounter = m.get(table);
            for(String food:foods) {
                if(foodCounter.containsKey(food))
                    curRow.add(foodCounter.get(food)+"");
                else 
                    curRow.add(0+"");
            }
            ans.add(curRow);
        }
        return ans;
    }
}
```
['Hash Table', 'Ordered Set', 'Java']