Code RoomResolve inherited sections
MediumPrep Room Coding #725

Resolve inherited sections

CodingAlgorithms & data structuresEntry–Mid~15 min

Environments in a deploy file can borrow from one another. The file is sectioned: "[title]" opens a section, "key=value" (first "=", trimmed) assigns inside it, blanks and "#" lines do nothing, repeated keys keep the last value. Inside a section, the special key "inherit" names ONE other section to borrow from. Resolve lookup(section, key) as: the section's own value if assigned; otherwise the borrowed section's own value if that section exists and assigned it; otherwise "". Borrowing is single-hop — never follow the borrowed section's own "inherit". Lookups are never for the key "inherit" itself.

Implement
lookup_with_inherit(lines: list[str], section: str, key: str) → str
Examples
in[["[base]","timeout=30","[prod]","inherit=base","host=p.example"],"prod","timeout"]out"30"
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 15 min
InputExpectedGot
[["[base]","timeout=30","[prod]","inherit=base","host=p.example"],"prod","timeout"]"30"not run yetsample