AO
Back

Message Type Parser: Field Types and Sizes

Also reported as Protobuf Parser · Message Parser

Phone ScreenPhone ScreenLast reported September 2026Medium Frequency

Problem Overview

The round: six reports: five phone screens and one onsite coding round. You get a string of protobuf-like message definitions, parse it yourself, and answer two queries: the size of a type and the type of a field. A table of primitive sizes is given. The follow-up in four of the reports is nested types: a field whose type is another message. One candidate only learned near the end that parsing the input string was part of the task, so settle that first. Two graded parts here.

What the tests call (you write all of it)

class MessageParser:
    def __init__(self, definitions: str, primitives: dict[str, int] | None = None): ...
    def get_size(self, name: str) -> int: ...
    def get_type(self, message_name: str, field_name: str) -> str: ...
  • definitions holds one or more definitions of the form Name : field_name field_type field_name2 field_type2 .... A new definition starts at any word followed by :, so definitions can sit on separate lines or run together on one line, as one report's input does: "Message : f1 int f2 Inner Inner : f3 char".
  • primitives defaults to the reported sizes: float 8, int 4, char 4.
  • get_size(name) takes a message name or a primitive name. A message's size is the sum of its fields' sizes.
  • get_type(message_name, field_name) returns the type name of that field.
  • An unknown name, a duplicate message or field, a field with no type, or an unknown field type raises ValueError.

Part 1 — primitive fields only

class MessageParser:   # every field type is a primitive
  • Every field type is a primitive. get_size("Vehicle") for "Vehicle : speed float id int" is 12; get_size("int") is 4.

Part 2 — nested message types

class MessageParser:   # a field type can be another message
  • A field's type can now be another message, defined before or after the one that uses it. Its size counts in full: "Outer : a int b Inner Inner : c float" gives Outer a size of 12.
  • A message that contains itself, directly or through others, has no finite size: here that raises ValueError when the string is parsed.

Notes: the method names, the two arguments of get_type and the primitive sizes are reported. The definition syntax beyond the reported example, the constructor, the ValueError contract and the cycle rule are ours. Another report writes the input as message vehicle field_name int ... and its get_type takes only a field name; ask which form you have.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 3
Trade-off discussion

Support nested types: a field whose type is another message.

Probes for: after get_size and get_type work on primitives

The input is a string: write the parser too.

Probes for: one interviewer said so near the end of the round

Messages can depend on messages defined later in the input.

Probes for: the nested follow-up

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
DFS with a memosizes computed on demand, each message once
Topological sort of messages by dependencyone candidate proposed it; the interviewer accepted something simpler
Re-scan until every size is knownsimple, easy to get wrong under time

What Reports Emphasize

Common mistakes: Assuming the definitions arrive already parsed (one candidate learned near the end that they did not); A re-scan loop for nested sizes that never got debugged in time; Slow progress: one candidate's feedback was gaps in the implementation and slow coding.

Edge cases to test: get_size on a primitive; Several definitions on one line; A nested message defined after its use; A message used in several places; A message that contains itself; Unknown message, field or type

Practice

Write your own against 11 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Applied Intuition with friends?

Send them this page. It is free to read, no account needed.

More Applied Intuition Questions

Free preview

Every question in the Applied Intuition catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 22 Applied Intuition questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Applied Intuition · Phone Screen · Reported 6× across candidate reports
Is this helpful?