PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates grid traversal and connected-component identification skills along with region-based aggregation (counting cells and summing crowns) in the Coding & Algorithms category.

  • medium
  • Airbnb
  • Coding & Algorithms
  • Software Engineer

Compute board-game score from regions

Company: Airbnb

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a 2D board for a board game. Each cell is encoded like `G1` or `W0`: - The first character is the **terrain/area type** (e.g., `G`, `W`, `S`). - The digit is the number of **crowns** in that cell (0–9). Two cells belong to the same **area/region** if they have the same terrain type and are connected by 4-directional adjacency (up/down/left/right). For each region: \[ \text{regionScore} = (\#\text{cells in region}) \times (\text{sum of crowns in region}) \] Return the **total score** across all regions. ### Example Board (rows): 1. `G1, G2, W0, W1, S1` 2. `G2, G3, W0, W1, S1` 3. `S2, S3, S1, G1, S1` 4. `G1, G2, W0, W1, S1` 5. `G1, G2, W0, W1, S1` Compute the total score for this board. ### Additional requirement Write a small set of self-contained test cases that cover edge cases (e.g., all same terrain, all crowns 0, single-cell regions, multiple disjoint regions of same terrain type).

Quick Answer: This question evaluates grid traversal and connected-component identification skills along with region-based aggregation (counting cells and summing crowns) in the Coding & Algorithms category.

You are given a rectangular 2D board for a board game. Each cell is encoded as a string like G1 or W0. The first character is the terrain type, and the digit(s) after it represent the number of crowns in that cell. Two cells belong to the same region if they have the same terrain type and are connected using 4-directional adjacency only: up, down, left, or right. Diagonal cells do not connect. For each region, compute: regionScore = (number of cells in the region) * (sum of crowns in the region) Return the total score across all regions. If the board is empty, return 0. Example board: [ ['G1', 'G2', 'W0', 'W1', 'S1'], ['G2', 'G3', 'W0', 'W1', 'S1'], ['S2', 'S3', 'S1', 'G1', 'S1'], ['G1', 'G2', 'W0', 'W1', 'S1'], ['G1', 'G2', 'W0', 'W1', 'S1'] ] The correct total score for this board is 116.

Constraints

  • 0 <= number of rows, number of columns <= 200
  • The board is rectangular
  • Each cell contains a terrain character followed by a crown count from 0 to 9
  • Cells are connected only in 4 directions, not diagonally

Examples

Input: [['G1', 'G2', 'W0', 'W1', 'S1'], ['G2', 'G3', 'W0', 'W1', 'S1'], ['S2', 'S3', 'S1', 'G1', 'S1'], ['G1', 'G2', 'W0', 'W1', 'S1'], ['G1', 'G2', 'W0', 'W1', 'S1']]

Expected Output: 116

Explanation: Regions are scored separately: top-left G=32, top W=8, middle-left S=18, right-column S=25, center G=1, bottom-left G=24, bottom W=8. Total = 116.

Input: []

Expected Output: 0

Explanation: An empty board has no regions, so the total score is 0.

Input: [['G1', 'G2'], ['G0', 'G3']]

Expected Output: 24

Explanation: All four cells are one G region. Size = 4, crowns = 1+2+0+3 = 6, so score = 4*6 = 24.

Input: [['S0', 'W0'], ['W0', 'S0']]

Expected Output: 0

Explanation: All cells have 0 crowns. Every region contributes 0 regardless of its size.

Input: [['G1', 'W0', 'G2'], ['W0', 'W0', 'W0'], ['G3', 'W0', 'G4']]

Expected Output: 10

Explanation: The four G cells are four separate single-cell regions scoring 1, 2, 3, and 4. The W region has 0 total crowns, so it contributes 0. Total = 10.

Hints

  1. This is a connected-components problem on a grid. Use DFS or BFS to explore one region at a time.
  2. While traversing a region, accumulate both the number of cells and the total crowns, then add their product to the answer.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Count Candies from Unlockable Boxes - Airbnb (medium)
  • Find Optimal Property Combination - Airbnb (medium)
  • Determine Exact Layover Booking - Airbnb (medium)
  • Solve Linked-List and Iterator Problems - Airbnb
  • Implement Text Layout and Query Parsing - Airbnb (easy)