PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Applied

Build message schema parser with size/type queries

Last updated: Mar 29, 2026

Quick Overview

This question evaluates parsing of a simple message schema, construction of mappings from field names to primitive types and byte sizes, and computation of aggregate sizes for composite message types.

  • medium
  • Applied
  • Coding & Algorithms
  • Software Engineer

Build message schema parser with size/type queries

Company: Applied

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a text definition of a message schema and a table of primitive types with their byte sizes. Implement a parser and expose two query functions: - `get_size(name)`: returns the size in bytes of either: - a primitive type (e.g., `"int"`), or - a field name defined in the message, or - the message type/name itself (total size = sum of its fields’ sizes). - `get_type(field_name)`: returns the declared type of the given field. ### Schema format The schema is provided as a multi-line string. Example: ``` Message: field_name field_type field_name2 field_type2 ``` - The first non-empty line is the message header (`Message:`). Treat the message type/name as `"Message"`. - Each subsequent non-empty line contains exactly two tokens: `<field_name> <field_type>`. - `<field_type>` is a primitive type listed in the primitives table. ### Primitives table You are given a map/dictionary like: - `float -> 8` - `int -> 4` - `char -> 4` ### Requirements 1. Parse the schema and store enough information to answer queries efficiently. 2. `get_size("Message")` returns the total size of the message (sum of sizes of each field’s type). 3. `get_size(field_name)` returns the size of that field’s type. 4. `get_type(field_name)` returns the type string for that field. 5. `get_size(primitive_type)` returns the size from the primitives table. ### Assumptions / edge behavior (make explicit in your implementation) - If a queried field/type does not exist, you may either raise an error/exception or return a sentinel value (e.g., `-1`/`null`), but be consistent. - Field names are unique within the message. - Whitespace and blank lines may appear and should be ignored. ### Example Given schema: ``` Message: price float qty int ``` and primitives `{float: 8, int: 4}`: - `get_type("price") -> "float"` - `get_size("price") -> 8` - `get_size("Message") -> 12` - `get_size("int") -> 4` Implement the parser and these two query functions.

Quick Answer: This question evaluates parsing of a simple message schema, construction of mappings from field names to primitive types and byte sizes, and computation of aggregate sizes for composite message types.

Related Interview Questions

  • Merge Overlapping Collinear Segments - Applied (hard)
  • Implement a Fixed-Capacity Deque - Applied (medium)
  • Implement Nested Transactional Key-Value Store - Applied (hard)
  • Merge overlapping 2D line segments - Applied (medium)
  • Find intersection of two line segments - Applied (easy)
Applied logo
Applied
Jan 6, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0
Loading...

You are given a text definition of a message schema and a table of primitive types with their byte sizes. Implement a parser and expose two query functions:

  • get_size(name) : returns the size in bytes of either:
    • a primitive type (e.g., "int" ), or
    • a field name defined in the message, or
    • the message type/name itself (total size = sum of its fields’ sizes).
  • get_type(field_name) : returns the declared type of the given field.

Schema format

The schema is provided as a multi-line string. Example:

Message:
  field_name  field_type
  field_name2 field_type2
  • The first non-empty line is the message header ( Message: ). Treat the message type/name as "Message" .
  • Each subsequent non-empty line contains exactly two tokens: <field_name> <field_type> .
  • <field_type> is a primitive type listed in the primitives table.

Primitives table

You are given a map/dictionary like:

  • float -> 8
  • int -> 4
  • char -> 4

Requirements

  1. Parse the schema and store enough information to answer queries efficiently.
  2. get_size("Message") returns the total size of the message (sum of sizes of each field’s type).
  3. get_size(field_name) returns the size of that field’s type.
  4. get_type(field_name) returns the type string for that field.
  5. get_size(primitive_type) returns the size from the primitives table.

Assumptions / edge behavior (make explicit in your implementation)

  • If a queried field/type does not exist, you may either raise an error/exception or return a sentinel value (e.g., -1 / null ), but be consistent.
  • Field names are unique within the message.
  • Whitespace and blank lines may appear and should be ignored.

Example

Given schema:

Message:
  price float
  qty   int

and primitives {float: 8, int: 4}:

  • get_type("price") -> "float"
  • get_size("price") -> 8
  • get_size("Message") -> 12
  • get_size("int") -> 4

Implement the parser and these two query functions.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Applied•More Software Engineer•Applied Software Engineer•Applied 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.