Detect a K-in-a-Row Win on a Rectangular Board

Quick Overview

Implement `winning_move(board, row, col, k)` after a valid move has placed a player's nonzero integer token at `(row, col)`. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.

Detect a K-in-a-Row Win on a Rectangular Board

Company: Databricks

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

# Detect a K-in-a-Row Win on a Rectangular Board Implement `winning_move(board, row, col, k)` after a valid move has placed a player's nonzero integer token at `(row, col)`. Return `true` iff that move creates at least `k` consecutive equal tokens horizontally, vertically, or on either diagonal. Constraints: `1 <= rows, cols <= 1000`; `1 <= k <= max(rows, cols)`. Inspect only lines through the last move and use `O(1)` extra space. ```hint Count both directions For each of four axes, combine the matching run on each side with the last move. ```

Quick Answer: Implement `winning_move(board, row, col, k)` after a valid move has placed a player's nonzero integer token at `(row, col)`. Work through the function contract, boundary cases, correctness argument, and time and space complexity expected in a production-quality solution.

|Home/Coding & Algorithms/Databricks
Databricks logo
Databricks
Jul 30, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Detect a K-in-a-Row Win on a Rectangular Board

Implement winning_move(board, row, col, k) after a valid move has placed a player's nonzero integer token at (row, col). Return true iff that move creates at least k consecutive equal tokens horizontally, vertically, or on either diagonal.

Constraints: 1 <= rows, cols <= 1000; 1 <= k <= max(rows, cols). Inspect only lines through the last move and use O(1) extra space.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...