Implement Connect Four with bottom push-up
Problem Description
Implement a variant of Connect Four with a unique "bottom push-up" mechanic. When a player drops a disc into a column, the new disc settles at the bottom of that column, pushing all existing discs in that column upwards by one position. If the column is already full, the disc at the very top is ejected from the board.
Your solution must design the board representation and provide APIs for the following functionalities:
- Initialization: Create a game board with
Rrows andCcolumns. The default dimensions should be 6 rows by 7 columns. - Drop Disc: Allow a specified player to drop a disc into a given column.
- Win Detection: After each move, detect if a player has achieved four discs in a row, either horizontally, vertically, or diagonally.
- Undo/Redo: Support the ability to undo the last move and redo a previously undone move.
Additionally, you must specify the time and space complexities of your operations, detail the data structures used, and explain how you handle various edge cases. These edge cases include, but are not limited to: ejected discs, attempts to drop into invalid columns, managing alternating player turns, and detecting a draw condition.
Provide code for the core operations.
AI interview prep
Core dilemma
Balancing the performance of dynamic board state manipulation (push-up, ejection) with efficient win detection and robust, potentially deep, undo/redo capabilities.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Connect Four with bottom push-up
Problem Description
Implement a variant of Connect Four with a unique "bottom push-up" mechanic. When a player drops a disc into a column, the new disc settles at the bottom of that column, pushing all existing discs in that column upwards by one position. If the column is already full, the disc at the very top is ejected from the board.
Your solution must design the board representation and provide APIs for the following functionalities:
- Initialization: Create a game board with
Rrows andCcolumns. The default dimensions should be 6 rows by 7 columns. - Drop Disc: Allow a specified player to drop a disc into a given column.
- Win Detection: After each move, detect if a player has achieved four discs in a row, either horizontally, vertically, or diagonally.
- Undo/Redo: Support the ability to undo the last move and redo a previously undone move.
Additionally, you must specify the time and space complexities of your operations, detail the data structures used, and explain how you handle various edge cases. These edge cases include, but are not limited to: ejected discs, attempts to drop into invalid columns, managing alternating player turns, and detecting a draw condition.
Provide code for the core operations.