Ctrl K

Kitchen Order Board

Medium
A café keeps its orders in a list orders, where orders[i] = [guest, table, dish]; the table number is stored as a string. The kitchen needs a summary table (every cell is a string): - the first row is a header: "Table" followed by the names of all ordered dishes, sorted as strings (by character code, so uppercase letters come before lowercase ones); - then one row per table that has at least one order, in increasing order of the table **number**: the table number, then for every dish in the header, how many times it was ordered at that table. Guest names do not appear in the table. Return it.
Example 1
orders=[["Mira", "7", "Pho"], ["Oleg", "2", "Lemonade"], ["Mira", "7", "Lemonade"], ["Ivo", "7", "Pho"]] → [['Table', 'Lemonade', 'Pho'], ['2', '1', '0'], ['7', '1', '2']]

Dishes in alphabetical order: Lemonade, Pho. Table 2 ordered one lemonade, table 7 one lemonade and two phos. Table 2 comes before 7 because tables are sorted as numbers.

Example 2
orders=[["Ann", "12", "Tea"], ["Bo", "3", "Tea"], ["Cy", "12", "Tea"]] → [['Table', 'Tea'], ['3', '1'], ['12', '2']]

One dish and two tables: 3 comes before 12, even though the string "12" is smaller than "3".

Example 3
orders=[["Zed", "1", "green tea"], ["Zed", "1", "Green tea"]] → [['Table', 'Green tea', 'green tea'], ['1', '1', '1']]
Constraints
  • 1 ≤ len(orders) ≤ 5 · 10⁴
  • len(orders[i]) = 3
  • guest names and dish names are 1 to 20 characters long and contain only English letters and spaces
  • the table number is an integer from 1 to 500 with no leading zeros
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAnagram Buckets MediumA Subsequence of One Word Only MediumMost Searched Words MediumWord Grown Letter by Letter MediumMerge Contact Cards Medium
loading Python…
Input
orders=[["Mira", "7", "Pho"], ["Oleg", "2", "Lemonade"], ["Mira", "7", "Lemonade"], ["Ivo", "7", "Pho"]]
Expected
[['Table', 'Lemonade', 'Pho'], ['2', '1', '0'], ['7', '1', '2']]

Run checks the first 3 tests in your browser. Submit checks all 56 tests on the server, hidden ones included.