Code RoomElement accessibility names
EasyPrep Room Coding #4718

Element accessibility names

CodingAlgorithms & data structuresEntry–Mid~16 min

An audit walks the accessibility tree of a settings page. Every element arrives as one string of five fields separated by a vertical bar: the element id, its role, its own text, its aria-label, and the id its aria-labelledby points at. The id and the role are always present, and any of the other three fields may be empty. Only the roles button, link, checkbox and textbox are audited, and every other role is left alone. An audited element takes its name from the labelledby target first, but only when that id appears in the list and the target's own text is not blank. Failing that it takes its aria-label when that is not blank, and failing that its own text. A value that is only whitespace counts as blank. Return the ids of the audited elements that end up with no name, in input order.

Implement
unnamed_controls(elements: list[str]) → list[str]
Examples
in[["b1|button|Save||","b2|button|||","h1|heading|Settings||"]]out["b2"]
in[["lbl|text|Email address||","in1|textbox|||lbl","in2|textbox|||missing"]]out["in2"]
in[["a1|link| |Open docs|","c1|checkbox| | |"]]out["c1"]
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 16 min
InputExpectedGot
[["b1|button|Save||","b2|button|||","h1|heading|Settings||"]]["b2"]not run yetsample
[["lbl|text|Email address||","in1|textbox|||lbl","in2|textbox|||missing"]]["in2"]not run yetsample
[["a1|link| |Open docs|","c1|checkbox| | |"]]["c1"]not run yetsample