Parse Indented YAML Mappings
Learn this problemProblem statement
Parse a valid YAML-like document yaml containing nested mappings. Each non-empty line has one of these forms:
key:opens a nested mapping;key: valuedefines a scalar value.
Indentation uses exactly two spaces per level. A child line is indented one level deeper than its containing mapping; indentation may later return to any earlier open level. Keys contain only letters, digits, underscores, and hyphens, and sibling keys are unique. Scalar values are non-empty trimmed text; quotes and # have no special meaning in this subset. Empty lines are ignored.
Return one string for each scalar line in document order. Use its full dot-separated key path, followed by = and the trimmed scalar value.
Function
parseYamlMappings(yaml: String) → String[]Examples
Example 1
yaml = "server:\n host: api.example.com\n port: 443\nmode: prod"return = ["server.host=api.example.com","server.port=443","mode=prod"]The two indented scalar keys belong under server; mode returns to the root level.
Example 2
yaml = "app:\n database:\n host: db\n enabled: true\n name: demo"return = ["app.database.host=db","app.database.enabled=true","app.name=demo"]The path stack grows through app.database and then returns one level for app.name.
Constraints
1 <= yaml.length <= 2 * 10^5.- The document contains at most
2 * 10^4non-empty lines. - The document satisfies the grammar and indentation rules stated above.
More Uber problems
- Minimum Refueling StopsONSITE INTERVIEW · Seen Jul 2026
- Last Truck to Leave the LaneOA · Seen Jul 2026
- Chain of CommandOA · Seen Jul 2026
- Jump Game with Prime-3 StepsOA · Seen Jun 2026
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026