The Display Table of Food Orders in a Restaurant coding problem asks you to generate a formatted table from a list of customer orders. Each order contains a customer name, a table number, and a food item. You need to create a summary where each row represents a table and each column represents a specific food item. The cells should contain the count of each food item ordered at that table. The table should be sorted by table number (numerically) and food items (alphabetically).
J.P. Morgan and other firms use this problem to test a candidate's ability to handle multi-dimensional data and sorting. It evaluations your mastery of Hash Table design patterns and your attention to detail regarding data types (e.g., table numbers as strings vs. integers). This is a practical, "real-world" problem that mirrors tasks like generating reports or pivot tables in a business application. It tests whether you can coordinate multiple maps and sets to build a structured output from flat data.
This problem relies on Nested Hash Maps and Sorted Sets.
TreeSet or a sorted list to collect all unique food items alphabetically.Map<Integer, Map<String, Integer>> to store the count of each food item per table. The outer key is the table number, and the inner key is the food item name.Orders: [["Alice", "3", "Pizza"], ["Bob", "3", "Burger"], ["Charlie", "1", "Pizza"]]
Practice using Map.getOrDefault() or similar constructs to simplify counter logic. For problems requiring two dimensions of sorting (rows and columns), always start by identifying the unique values for both dimensions and sorting them before attempting to build the final result.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Group Anagrams | Medium | Solve | |
| Alert Using Same Key-Card Three or More Times in a One Hour Period | Medium | Solve | |
| Before and After Puzzle | Medium | Solve | |
| Find And Replace in String | Medium | Solve | |
| Groups of Special-Equivalent Strings | Medium | Solve |