class MessageParser:
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.ValueError.Part 1 — primitive fields only
class MessageParser: # every field type is a primitive
get_size("Vehicle") for "Vehicle : speed float id int" is 12; get_size("int") is 4.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.
Reported at the phone screen in most threads and once as the third onsite coding round. One screen was 45 minutes and the candidate finished the nested follow-up but had no time to run tests; they passed. Another interviewer read the problem aloud quickly and only said near the end that the input had to be parsed; that candidate expected to fail. One candidate's feedback was that the implementation had gaps and was slow. For the nested follow-up, one candidate proposed a topological sort and was told a simpler approach was fine; their re-scan loop had a bug they could not fix in time, and they later thought DFS with lazy evaluation was the better route.
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
Alternative approaches: DFS with a memo (sizes computed on demand, each message once); Topological sort of messages by dependency (one candidate proposed it; the interviewer accepted something simpler); Re-scan until every size is known (simple, easy to get wrong under time)
Also reported as Protobuf Parser · Message Parser
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.ValueError.Part 1 — primitive fields only
class MessageParser: # 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
"Outer : a int b Inner Inner : c float" gives Outer a size of 12.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.
Support nested types: a field whose type is another message.
The input is a string: write the parser too.
Messages can depend on messages defined later in the input.
| Approach | Notes |
|---|---|
| DFS with a memo | sizes computed on demand, each message once |
| Topological sort of messages by dependency | one candidate proposed it; the interviewer accepted something simpler |
| Re-scan until every size is known | simple, easy to get wrong under time |
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
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.
Send them this page. It is free to read, no account needed.
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.