Price a Nested Menu Customization String With a Parser
Last updated: November 29, 2026
Quick Overview
Given an item string like 'Burrito:1099(Guac:250,Extra Meat:300x2)x2', where each item has a price in cents, optional nested modifiers in parentheses, and an optional quantity, parse it and return the total price in cents, rejecting malformed input.
DoorDash
November 29, 20260
0
0 solved
Given an item string like 'Burrito:1099(Guac:250,Extra Meat:300x2)x2', where each item has a price in cents, optional nested modifiers in parentheses, and an optional quantity, parse it and return the total price in cents, rejecting malformed input.
DoorDash menus are deeply nested (item, option group, option, sub-option), and a parsing question like this checks whether you can write a small recursive descent parser instead of fragile splits. Interviewers look for a clear grammar, a single position cursor, and helpful errors.
What the Interviewer Expects
- Write the grammar down before coding
- Use recursive descent with one shared index
- Apply quantities to the item plus all of its modifiers
- Report errors with the position that failed
- Reject trailing characters after a complete item
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return a structured tree instead of a total?
- How would you add escaping so names can contain commas or parentheses?
- How would you validate against a real menu schema with min and max selections?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Grammar:
item := name ':' cents [ '(' item {',' item} ')' ] [ 'x' qty ]. - Names may contain spaces but not
: ( ) ,. - A modifier's total (with its own quantity) adds to its parent; the parent's...
High-Level Design
Keep a single cursor pos shared by nested helper functions. parse_item reads a name up to a colon, a price, an optional parenthesized list of child items (recursing on each), and an optional x q...