← Questions

Score a tile board by connected terrain regions

0
WaymoAirbnbCodingLast asked Mar 2026

A coding interview question asked in Airbnb's technical phone screen and at Waymo, last asked Mar 2026. It tests grid, bfs and connected components.

A tile-laying board game ends when every player has filled a rectangular board. You must compute a player's final score.

You are given board, a 2D list of strings with R rows and C columns. Each tile is a 2-character string:

  • The first character is an uppercase letter, the tile's terrain (for example W for water, G for grassland, F for forest).
  • The second character is a digit 0-9, the number of crowns on the tile.

Two tiles are in the same region when they share an edge (up, down, left or right, not diagonal) and have the same terrain letter. Regions are maximal: they include every tile reachable this way. Two regions of the same terrain that do not touch are scored separately.

A region scores (number of tiles in the region) * (total crowns in the region). A region with no crowns scores 0. The board score is the sum of all region scores.

Implement:

def calculate_board_score(board: list[list[str]]) -> int:
    ...

Constraints

  • 0 <= R, C <= 1000; all rows have the same length.
  • Raise ValueError for a malformed tile or ragged rows.
  • Do not modify the input.

Example 1

board = [["W1", "W0", "G0"],
         ["G0", "G2", "G0"],
         ["W0", "F0", "F1"]]
-> 12

The top-left water region has 2 tiles and 1 crown (2 points). The grassland region has 4 tiles and 2 crowns (8 points). The bottom-left water tile touches no other water, so it is its own region with 0 crowns (0 points). The forest region has 2 tiles and 1 crown (2 points).

Example 2

board = [["S1", "W0"],
         ["W0", "S1"]]
-> 2

The two S tiles touch only at a corner, so each is a separate region worth 1 * 1.

Clarifying questions

  • Is an empty board (R = 0 or C = 0) valid, with a score of 0?
  • What counts as a malformed tile: wrong length, a lower-case terrain letter, a non-digit crown count?
  • Can the board be as large as 1000 x 1000, so recursion could overflow the stack?
  • Are there any special tiles (such as a castle) that join no region?

What a strong answer covers

  • Validates every tile and the row lengths before scoring.
  • Finds regions with an iterative flood fill (BFS or a stack) over the four neighbors with the same terrain, using a separate visited grid so the input isn't modified. Union-find is a good alternative.
  • For each region, counts tiles and adds up crowns, then adds tiles * crowns to the score.
  • O(R * C) time and space, with no recursion, so a 1000 x 1000 board of one terrain is fine.
  • Tests: both examples, an empty board, a board of one terrain, a snake-shaped region, diagonal-only contact, ragged rows and a malformed tile.

Follow-ups

  • Report the score for each terrain, or the largest region.
  • Tiles are placed one at a time: keep the score up to date after each placement (union-find with tile and crown totals).
  • Add bonus rules, such as points for a full board or for the castle in the center.
  • Score several players' boards and rank them.

Where it's asked

What it tests

grid · bfs · connected components

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding