Question presented to candidate: "Build Connect Four for two players on one screen. It is a 7 column by 6 row board standing upright: you pick a column, the disc falls to the lowest free spot, and the first player to line up four discs in any direction wins. Show whose turn it is, highlight the winning four, and handle full columns and a full board."
Requirements:
- A 7 x 6 board; Red moves first, then Red and Yellow alternate.
- Choosing a column drops the disc into the lowest empty slot of that column; a full column refuses the move.
- Detect four in a row horizontally, vertically or on either diagonal, and highlight those four discs.
- Detect a draw when all 42 slots are filled with no winner.
- A status line, a screen-reader announcement of each move, and a New game button.
What a strong answer should cover:
- Board representation (a flat array or rows of columns) and the "lowest empty row" gravity function.
- A win check that only looks at lines through the disc just dropped: 4 directions, both ways, O(1) for a fixed board.
- Immutable updates: each drop returns a new game object; illegal drops return the same one.
- Draw detection by move count, and turn switching that stops on a win.
- Accessible input: one button per column with a label like "Column 3, 4 empty", and focus that survives a column filling up.
Clarifying questions expected:
- "Should the board size and the number to connect be configurable?"
- "Do you want a drop animation, or is an instant drop fine for now?"
- "Is undo or a move history needed?"
Code / implementation expected: Yes. A working board with gravity and win detection; the interviewer usually asks you to explain the win check and its cost.