Count Distinct Domino Colorings
Learn this problemProblem statement
In Amazon's warehouse automation systems, robotic movement paths are modeled using domino-like tiles placed on a grid.
A domino is a unique 1x2 or 2x1 piece represented by an English character, lowercase or uppercase. A valid domino arrangement is represented by two strings in the array domino.
Treat domino[0] as the top row and domino[1] as the bottom row of a 2 * n grid. Both strings have the same length n.
Each character appears exactly twice and identifies one domino. The two strings always describe a complete, non-overlapping tiling of the 2 x n grid:
- There is a vertical domino at column
iifdomino[0][i] == domino[1][i]. - There is a horizontal domino spanning columns
iandi + 1ifdomino[0][i] == domino[0][i + 1]anddomino[1][i] == domino[1][i + 1].
Two dominoes are adjacent if they share a side in this grid, up, down, left, or right. Diagonal contact does not count.
Each domino can be colored using one of three colors: Red, Green, or Blue, represented as RGB. Both halves of a domino must be the same color, and adjacent dominoes must have different colors.
Find the number of distinct ways to color the dominoes such that no two adjacent dominoes have the same color. Return the answer modulo 10^9 + 7.
Function
countDistinctColorings(domino: String[]) → intExamples
Example 1
domino = ["abb", "acc"]return = 6The arrangement can be visualized as:
a b b (top)a c c (bottom)
The valid colorings are:
[RGG, RBB][RBB, RGG][GRR, GBB][GBB, GRR][BGG, BRR][BRR, BGG]
The first domino, a, is arranged vertically. The b and c dominoes are horizontal. The answer is 6.
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026