Screen reader queue settle
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.
live_region_flush(entries: list[str]) → list[str][["cart|polite|One item added","cart|polite|Two items added","toast|polite|Saved"]]out["Two items added","Saved"][["toast|polite|Draft saved","alerts|assertive|Session expiring","cart|polite|Cart cleared"]]out["Session expiring","Cart cleared"][["status|polite|Uploading","status|polite| ","toast|polite|Link copied"]]out["Link copied"]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.
[["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