Flatten a Nested Scenario Parameter Config Into Dotted Keys

Last updated: November 29, 2026

Quick Overview

Parse a compact nested config string such as {ego:{speed:12.5,lane:2},weather:"light rain"} into a flat dictionary with dotted keys, typed values (int, float, bool, quoted string), and clear errors for malformed input or duplicate keys.

Applied Intuition
Coding & Algorithms
Software Engineer
Applied Intuition
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Parse a compact nested config string such as {ego:{speed:12.5,lane:2},weather:"light rain"} into a flat dictionary with dotted keys, typed values (int, float, bool, quoted string), and clear errors for malformed input or duplicate keys.

Scenario authoring at Applied Intuition involves parameterized scenario files that tooling must parse and validate. The interviewer is checking a hand-written recursive descent parser: position tracking, whitespace handling, typed scalars and helpful error messages.

What the Interviewer Expects
  • Write a small recursive descent parser rather than using regex for nesting
  • Track a position index and skip whitespace consistently
  • Parse typed scalars including quoted strings with spaces
  • Report the position of errors and reject duplicate keys
  • Reject trailing garbage after the top-level object
Key Topics to Cover
string parsing
recursive descent
tokenization
error handling
config validation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you add arrays like lanes:[1,2,3]?
  • How would you support escaped quotes inside strings?
  • How would you validate values against a schema with ranges?
  • How would you re-serialize the flat map back to nested form?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Grammar: obj := '{' (pair (',' pair)*)? '}', pair := ident ':' (obj | scalar). Keys are alphanumeric or underscore. Scalars: true, false, ints, floats, double-quoted strings without escapes. O...

High-Level Design

One function per grammar rule sharing a cursor. obj reads a key, a colon, then either recurses on { or reads a scalar, then expects , or }. Nested keys are built by joining the prefix, so flat...


Submit Your Answer
Markdown supported