Code RoomDocument style stack
EasyPrep Room Coding #4799

Document style stack

CodingAlgorithms & data structuresEntry–Mid~15 min

A document renderer walks a page of nested sections and reports what style is in force at each point. Each entry in events is one of three strings. "enter|font=serif" opens a section that binds one attribute, written as the attribute name, an equals sign, then the value. Neither the name nor the value contains a pipe or an equals sign. "leave" closes the innermost section still open, and does nothing when no section is open. "ask|font" asks what that attribute is right now, which is the value bound by the innermost section still open that binds it. Return the answers to the asks, in the order the asks appear, using the string "inherit" when no open section binds the attribute asked for.

Implement
resolve_scoped_styles(events: list[str]) → list[str]
Examples
in[["enter|font=serif","ask|font","leave","ask|font"]]out["serif","inherit"]
in[["enter|color=teal","enter|color=rust","ask|color","leave","ask|color"]]out["rust","teal"]
in[["enter|font=mono","ask|color","ask|font"]]out["inherit","mono"]
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
[["enter|font=serif","ask|font","leave","ask|font"]]["serif","inherit"]not run yetsample
[["enter|color=teal","enter|color=rust","ask|color","leave","ask|color"]]["rust","teal"]not run yetsample
[["enter|font=mono","ask|color","ask|font"]]["inherit","mono"]not run yetsample