Keyboard focus order

Write codeEasy14 minMicrosoft and Apple style

Your task

A design system ships a checkout form, and a test harness reproduces sequential focus navigation over it so the team can assert the keyboard path without a browser. You receive the element ids in document order, the tabindex value each element declares, and whether each element is disabled. The three lists always have the same length. A disabled element is never reached, and neither is an element whose tabindex is negative. Elements declaring a positive tabindex are reached first, ordered by that value from low to high, and two elements declaring the same value keep their document order. Every element declaring tabindex 0 is reached after all of those, in document order. Return the ids in the order the Tab key reaches them.

Examples

keyboard_tab_order(ids: list[str], tab_index: list[int], disabled: list[bool]) -> list[str]
Example 1
Inputkeyboard_tab_order(["email", "card", "submit"], [0, 0, 0], [False, False, False])
Output["email", "card", "submit"]
Example 2
Inputkeyboard_tab_order(["skip", "logo", "search", "cart"], [1, 0, 2, 0], [False, False, False, False])
Output["skip", "search", "logo", "cart"]
Example 3
Inputkeyboard_tab_order(["a", "b", "c"], [0, -1, 0], [False, False, True])
Output["a"]