Magicsheet logo

Check if Two Chessboard Squares Have the Same Color

Easy
12.5%
Updated 8/1/2025

Asked by 3 Companies

Check if Two Chessboard Squares Have the Same Color

What is this problem about?

Given the coordinates of two squares on a standard 8imes88 imes 8 chessboard (e.g., "a1" and "c3"), you need to determine if they have the same color. On a chessboard, the bottom-left square "a1" is black, and colors alternate both horizontally and vertically.

Why is this asked in interviews?

Companies like Meta and Amazon use this "Easy" problem to test basic string parsing and parity logic. It's a test of whether you can translate a visual pattern into a simple mathematical formula. It evaluations your ability to map characters (a-h) and digits (1-8) into a coordinate system and use the properties of even/odd sums.

Algorithmic pattern used

The pattern is Parity-based Math. In a grid where colors alternate, a square (x,y)(x, y) is one color if x+yx+y is even, and the other color if x+yx+y is odd. You just need to convert the column letter to an integer (a=0, b=1, etc.) and the row digit to an integer, then check if the parities of the sums (x1+y1)(x1+y1) and (x2+y2)(x2+y2) match.

Example explanation

Square 1: "a1" -> x=0, y=0. Sum = 0 (Even). Square 2: "c3" -> x=2, y=2. Sum = 4 (Even). Both sums are even, so they have the same color. Square 3: "h3" -> x=7, y=2. Sum = 9 (Odd). "a1" and "h3" have different colors.

Common mistakes candidates make

A common error is overcomplicating the logic by trying to build the entire chessboard in memory. Another mistake is miscalculating the indices (e.g., thinking 'a' is 1 and 'b' is 2, which is fine, but being inconsistent). Some might also forget that the color depends on the sum of the coordinates, not just the individual parities.

Interview preparation tip

Many grid-based "color" or "pattern" problems can be solved using the formula (row + col) % 2. This is a powerful trick for any alternating pattern in two dimensions.

Similar Questions