Question presented to candidate: "Build a small grid of lights, 3 by 3 with the middle cell empty. Clicking a cell turns it on. When every light is on, they should turn off one by one in the reverse of the order they were clicked, one every 300 milliseconds. While they are turning off, clicks should be ignored."
Requirements:
- Render the grid from a config array (1 = light, 0 = empty slot); the default is a 3 x 3 ring with a hole in the centre.
- Clicking an off light turns it on; clicking a light that is already on does nothing.
- When all lights are on, deactivate them in reverse activation order at a fixed 300 ms interval.
- Ignore clicks during deactivation; after the last light turns off, the grid accepts clicks again.
- Clean up timers if the component unmounts.
What a strong answer should cover:
- Storing the activation ORDER as the state (an array of indices) so "is it on" and "which goes off next" are both derived from it.
- The deactivation as a stack: last in, first out, one pop per tick.
- Timer choice and cleanup: a chained
setTimeoutper step or onesetInterval, cleared on completion and on unmount. - A
deactivatingflag (or derived phase) that locks input, and why it is needed. - Accessibility: buttons with
aria-pressedfor on/off, a label per cell, andaria-disabledwhile locked.
Clarifying questions expected:
- "Is the interval fixed at 300 ms, and should the first light go off immediately or after one interval?"
- "Can the grid shape change, for example a 4 x 4 config?"
- "Should a click during deactivation be ignored, or should it cancel the sequence?"
Code / implementation expected: Yes. A working grid with the timed reverse deactivation; expect questions about timer cleanup.