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

Last updated: July 30, 2026

Quick Overview

The question asks the candidate to implement a function that detects if there is a K-in-a-row win on a rectangular board, typically used in games like Connect Four.

Databricks
Coding & Algorithms
Software Engineer
Databricks
July 30, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

7

0

82 solved


The question asks the candidate to implement a function that detects if there is a K-in-a-row win on a rectangular board, typically used in games like Connect Four.

This question is commonly asked during onsite interviews for software engineering roles, particularly at companies like Databricks that value problem-solving skills and algorithmic thinking. The interviewer is evaluating the candidate's ability to devise an efficient solution, understand the problem requirements, and implement a clean and correct algorithm. It also tests the candidate's ability to think critically about edge cases and performance considerations.

What the Interviewer Expects
  • Clearly define the problem and constraints.
  • Design an efficient algorithm to check for K-in-a-row.
  • Implement the solution in a clean and readable manner.
  • Discuss time and space complexity of the solution.
  • Consider edge cases and explain how they are handled.
Key Topics to Cover
Algorithm Design
2D Arrays
Game Theory
Complexity Analysis
Edge Cases
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you optimize your solution for larger boards?
  • Can you explain how you would handle invalid inputs?
  • What changes would you make if the board size were dynamic?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Approach

To solve the K-in-a-row problem, we need to check for K consecutive markers in any direction: horizontally, vertically, and diagonally. We will iterate through each cell of the board and check in all ...

Algorithm

We can implement the solution using a nested loop to traverse the board. For each cell, we will check for K consecutive markers in all four directions. Here's a Python implementation:

def c...

Submit Your Answer
Markdown supported

Related Questions