Code RoomScreen reader queue settle
EasyPrep Room Coding #4795

Screen reader queue settle

CodingAlgorithms & data structuresEntry–Mid~15 min

A screen reader has one output channel, so a page that updates several live regions in the same batch has to work out what actually gets read aloud. Each queued entry is one string: the region id, a vertical bar, the politeness which is either polite or assertive, another bar, then the text. Any further bar belongs to the text. Settle the queue in three steps. An assertive entry interrupts, so drop every entry sitting before the last assertive one. Of what remains, keep only the last entry naming each region, because a region announces its current contents and not its history. Then drop the entries whose text is empty or only whitespace, since there is nothing to say. Return the surviving texts unchanged, in queue order.

Implement
live_region_flush(entries: list[str]) → list[str]
Examples
in[["cart|polite|One item added","cart|polite|Two items added","toast|polite|Saved"]]out["Two items added","Saved"]
in[["toast|polite|Draft saved","alerts|assertive|Session expiring","cart|polite|Cart cleared"]]out["Session expiring","Cart cleared"]
in[["status|polite|Uploading","status|polite| ","toast|polite|Link copied"]]out["Link copied"]
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
[["cart|polite|One item added","cart|polite|Two items added","toast|polite|Saved"]]["Two items added","Saved"]not run yetsample
[["toast|polite|Draft saved","alerts|assertive|Session expiring","cart|polite|Cart cleared"]]["Session expiring","Cart cleared"]not run yetsample
[["status|polite|Uploading","status|polite| ","toast|polite|Link copied"]]["Link copied"]not run yetsample