PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/CloudKitchens

Implement menu parser and serializer

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in text parsing, hierarchical data modeling, tree construction and serialization, string manipulation, and algorithmic complexity (linear time/space).

  • medium
  • CloudKitchens
  • Coding & Algorithms
  • Software Engineer

Implement menu parser and serializer

Company: CloudKitchens

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

### Menu parser and serializer You are given a restaurant menu stored as plain text, where indentation represents a hierarchy of categories and items. Implement logic to convert between this text format and a tree data structure. #### Text format - The menu is a multi-line string; each non-empty line describes one menu item. - Leading indentation (0 or more groups of two spaces) indicates nesting depth relative to top-level categories. - After the indentation, fields on each line are separated by the `|` character: `<type>|<id>|<name>|<price>` where: - `type` is a string label such as `CATEGORY`, `FOOD`, or `SIDE` (you should not assume only these three types; treat it as an arbitrary string). - `id` is a unique identifier string for this item. - `name` is free text that does not contain the `|` character. - `price` is a decimal number (e.g., `5.99`), or the literal `-` if the item does not have a price (e.g., a category). Example input: ```text CATEGORY|c1|Burgers|- FOOD|f1|Classic Burger|5.99 SIDE|s1|Fries|1.99 FOOD|f2|Veggie Burger|6.49 CATEGORY|c2|Drinks|- FOOD|f3|Cola|1.50 FOOD|f4|Water|1.00 ``` This example represents a hierarchy like `category > food > side`, but in general the depth and item types can vary. #### Tree structure Define a data structure `MenuItem` (language-agnostic) with at least the following fields: - `type`: string - `id`: string - `name`: string - `price`: nullable/optional number (null if the text price is `-`) - `children`: an ordered list/array of `MenuItem` representing nested items Top-level menu items are those with zero indentation. #### Tasks 1. Implement a function (e.g., `parseMenu(text)`) that takes the menu text string and returns the corresponding tree: a list/array of top-level `MenuItem` nodes, each with properly populated `children`. 2. Implement a function (e.g., `serializeMenu(items)`) that takes the tree (the list/array of top-level `MenuItem` nodes) and returns a canonical text representation in exactly the same format as described above. The serializer must: - Use exactly two spaces per level of indentation deeper than a parent. - Use `|` as the field separator. - Output `-` for items whose `price` is null/absent. - Output a depth-first traversal, where all children of a node appear immediately after their parent, in the order stored in `children`. You may assume the input text is always a valid, well-formed tree (no cycles, consistent indentation, and at least one top-level item). Design your parsing and serialization logic to run in O(N) time and O(N) extra space, where N is the number of menu items (lines) in the input.

Quick Answer: This question evaluates proficiency in text parsing, hierarchical data modeling, tree construction and serialization, string manipulation, and algorithmic complexity (linear time/space).

Related Interview Questions

  • Design a menu manager with enums - CloudKitchens (Medium)
  • Design an in-memory cloud storage system - CloudKitchens (Medium)
  • Design receipt system with combo discounts - CloudKitchens (Medium)
  • Implement concurrent order-accept/pickup simulator - CloudKitchens (medium)
  • Answer static and streaming Top-K queries - CloudKitchens (medium)
CloudKitchens logo
CloudKitchens
Nov 7, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0

Menu parser and serializer

You are given a restaurant menu stored as plain text, where indentation represents a hierarchy of categories and items. Implement logic to convert between this text format and a tree data structure.

Text format

  • The menu is a multi-line string; each non-empty line describes one menu item.
  • Leading indentation (0 or more groups of two spaces) indicates nesting depth relative to top-level categories.
  • After the indentation, fields on each line are separated by the | character: <type>|<id>|<name>|<price> where:
    • type is a string label such as CATEGORY , FOOD , or SIDE (you should not assume only these three types; treat it as an arbitrary string).
    • id is a unique identifier string for this item.
    • name is free text that does not contain the | character.
    • price is a decimal number (e.g., 5.99 ), or the literal - if the item does not have a price (e.g., a category).

Example input:

CATEGORY|c1|Burgers|-
  FOOD|f1|Classic Burger|5.99
    SIDE|s1|Fries|1.99
  FOOD|f2|Veggie Burger|6.49
CATEGORY|c2|Drinks|-
  FOOD|f3|Cola|1.50
  FOOD|f4|Water|1.00

This example represents a hierarchy like category > food > side, but in general the depth and item types can vary.

Tree structure

Define a data structure MenuItem (language-agnostic) with at least the following fields:

  • type : string
  • id : string
  • name : string
  • price : nullable/optional number (null if the text price is - )
  • children : an ordered list/array of MenuItem representing nested items

Top-level menu items are those with zero indentation.

Tasks

  1. Implement a function (e.g., parseMenu(text) ) that takes the menu text string and returns the corresponding tree: a list/array of top-level MenuItem nodes, each with properly populated children .
  2. Implement a function (e.g., serializeMenu(items) ) that takes the tree (the list/array of top-level MenuItem nodes) and returns a canonical text representation in exactly the same format as described above.

The serializer must:

  • Use exactly two spaces per level of indentation deeper than a parent.
  • Use | as the field separator.
  • Output - for items whose price is null/absent.
  • Output a depth-first traversal, where all children of a node appear immediately after their parent, in the order stored in children .

You may assume the input text is always a valid, well-formed tree (no cycles, consistent indentation, and at least one top-level item).

Design your parsing and serialization logic to run in O(N) time and O(N) extra space, where N is the number of menu items (lines) in the input.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More CloudKitchens•More Software Engineer•CloudKitchens Software Engineer•CloudKitchens Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.