C# - Using Dictionary and HashSet to generate required table
csharp\npublic IList<IList<string>> DisplayTable(IList<IList<string>> orders)\n{\n\tHashSet<string> foodItems = new HashSet<string>();\n\tDictionary<int, Dictio
```csharp\npublic IList<IList<string>> DisplayTable(IList<IList<string>> orders)\n{\n\tHashSet<string> foodItems = new HashSet<string>();\n\tDictionary<int, Dictionary<string, int>> table = new Dictionary<int, Dictionary<string, int>>();\n\n\tforeach (var order in orders)\n\t{\n\t\tint tableNumber = Convert.ToInt32(order[1]);\n\t\tstring food = order[2];\n\t\tfoodItems.Add(food);\n\n\t\tif (!table.ContainsKey(tableNumber))\n\t\t{\n\t\t\ttable.Add(tableNumber, new Dictionary<string, int>());\n\t\t}\n\n\t\tvar currentTable = table[tableNumber];\n\t\tif (currentTable.ContainsKey(food))\n\t\t{\n\t\t\tcurrentTable[food]++;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcurrentTable.Add(food, 1);\n\t\t}\n\t}\n\n\tIList<IList<string>> result = new List<IList<string>>();\n\tList<string> firstRow = new List<string>() { "Table" };\n\tvar sortedFoodItems = foodItems.OrderBy(x => x, StringComparer.Ordinal).ToArray();\n\tfirstRow.AddRange(sortedFoodItems);\n\tresult.Add(firstRow);\n\n\tvar keys = table.Keys.OrderBy(x => x).ToArray();            \n\tstring zeroString = "0";\n\n\tforeach (var key in keys)\n\t{\n\t\tList<string> tableRow = new List<string>();\n\t\ttableRow.Add(key.ToString());\n\t\tforeach (var foodItem in sortedFoodItems)\n\t\t{\n\t\t\tvar currentTable = table[key];\n\t\t\tif (currentTable.ContainsKey(foodItem))\n\t\t\t{\n\t\t\t\ttableRow.Add(currentTable[foodItem].ToString());\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ttableRow.Add(zeroString);\n\t\t\t}\n\t\t}\n\n\t\tresult.Add(tableRow);\n\t}\n\n\treturn result;\n}\n```
[]