InterviewDB
Experience
Menu Parser: Parse a Hierarchical Restaurant Menu from Raw Text into a Structured Object
phone
Interview Experience
Problem
You are given a multi-line string representing a restaurant menu. Sections are indicated by lines in ALL CAPS, and items follow as item_name: $price. Parse it into a nested dictionary: {section_name: [{name: str, price: float}]}.
python
def parse_menu(raw: str) -> dict[str, list[dict]]:
pass
Example:
raw = """
APPETIZERS
Spring Rolls: $6.50
Soup of the Day: $4.00
MAIN COURSE
Grilled Salmon: $18.00
Pasta Primavera: $14.50
"""
-> {
"APPETIZERS": [{"name": "Spring Rolls", "price": 6.50},
{"name": "Soup of the Day", "price": 4.00}],
"MAIN COURSE": [{"name": "Grilled Salmon", "price": 18.00},
{"name": "Pasta Primavera", "price": 14.50}]
}
Follow-ups
- How do you handle items that appear before any section header?
- What if prices use different currencies or formats (e.g.,
EUR 6,50)? How do you make price parsing robust? - How would you extend this to support sub-sections (indented ALL CAPS headers)?
- If this parser is used in a scraping pipeline, what logging and error recovery would you add for malformed input lines?
Full Details
Problem
You are given a multi-line string representing a restaurant menu. Sections are indicated by lines in ALL CAPS, and items follow as item_name: $price. Parse it into a nested dictionary: {section_name: [{name: str, price: float}]}.
python
def parse_menu(raw: str) -> dict[str, list[dict]]:
pass
Example:
raw = """
APPETIZERS
Spring Rolls: $6.50
Soup of the Day: $4.00
MAIN COURSE
Grilled Salmon: $18.00
Pasta Primavera: $14.50
"""
-> {
"APPETIZERS": [{"name": "Spring Rolls", "price": 6.50},
{"name": "Soup of the Day", "price": 4.00}],
"MAIN COURSE": [{"name": "Grilled Salmon", "price": 18.00},
{"name": "Pasta Primavera", "price": 14.50}]
}
Follow-ups
- How do you handle items that appear before any section header?
- What if prices use different currencies or formats (e.g.,
EUR 6,50)? How do you make price parsing robust? - How would you extend this to support sub-sections (indented ALL CAPS headers)?
- If this parser is used in a scraping pipeline, what logging and error recovery would you add for malformed input lines?
Free preview. Unlock all Cloudkitchens questions →
About This Question
This is a candidate experience report from a cloudkitchens interview during the phone round.