Based on real interviews
Find a Connect K winner
Follow a sequence of moves and identify the first player to form a winning line on a configurable board.
Unlock with Full AccessThe challenge
Two players drop pieces into columns, where each piece falls to the lowest available position. The board dimensions and the required line length can change. Implement the game logic that updates the board and detects a horizontal, vertical or diagonal win as moves arrive.
What you'll practise
Board state
Place alternating players' pieces in the correct positions as columns fill.
Directional checks
Detect winning lines across rows, columns and both diagonal directions.
Game boundaries
Handle different board sizes, short winning lines and games without a winner.
def connect_k_winner(
rows, columns, k, moves
):
# Your implementation goes here
passRun your code to see results.