You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.

Return true if the square is white, and false if the square is black.
The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.
Example 1:
Input: coordinates = "a1" Output: false Explanation: From the chessboard above, the square with coordinates "a1" is black, so return false.
Example 2:
Input: coordinates = "h3" Output: true Explanation: From the chessboard above, the square with coordinates "h3" is white, so return true.
Example 3:
Input: coordinates = "c7" Output: false
Constraints:
coordinates.length == 2'a' <= coordinates[0] <= 'h''1' <= coordinates[1] <= '8'Problem Overview: A chessboard coordinate like "a1" or "h3" is given. The first character represents the column (a–h) and the second represents the row (1–8). The task is to determine whether that square is white or black on a standard chessboard.
Approach 1: Index-Based Calculation (Time: O(1), Space: O(1))
Convert the column letter into a numeric index using ASCII arithmetic (column - 'a' + 1). Convert the row character into an integer. Once both coordinates are numeric, add them together. On a chessboard, squares with an even sum are black and squares with an odd sum are white (or vice versa depending on indexing choice, but the parity relationship stays consistent). This approach relies on simple math operations and minimal string parsing.
Approach 2: Parity of Coordinates (Time: O(1), Space: O(1))
Observe the pattern of a chessboard: colors alternate every step horizontally and vertically. Convert the column letter and row digit into integers, then check whether both have the same parity (both even or both odd). If the parity matches, the square has one color; if different, it has the other. The key insight is that color changes whenever you move one step in either direction, so parity fully determines the color. This approach expresses the logic directly with a parity check such as (col + row) % 2.
Recommended for interviews: The parity-based approach is what most interviewers expect. It shows you recognized the alternating chessboard pattern and reduced the problem to a constant-time arithmetic check. The index-based calculation demonstrates the same idea but makes the coordinate conversion step explicit. Both run in O(1) time and O(1) space.
The chessboard can be considered as an 8x8 grid where each square is identified by a combination of a letter (column 'a' to 'h') and a number (row '1' to '8').
One method to determine if the square is black or white is to map these coordinates to indices: columns can be mapped to numbers (a=1, b=2, ..., h=8), and rows are directly represented by numbers (1 to 8). The color of a square can be determined by the sum of these mapped values. If the sum is even, the square is black; if odd, it is white.
The function squareIsWhite checks if the given coordinates point to a white square on a chessboard. The column character is converted into a number (1-8), the row is already a number, and their sum is evaluated. The result is true if the sum is odd, indicating a white square.
Time Complexity: O(1), since the algorithm performs a constant amount of work.
Space Complexity: O(1), since no additional space is used besides a few variable allocations.
Another approach is to explicitly define the parity rule. We analyze the position and discern that squares in the same diagonal alternation such as (0,0), (1,1), ..., are of the same color. Here, shifting the ASCII value shifts the problem to decide via binary even-odd pairing.
This method capitalizes on the fact that using the ASCII values of the characters directly, we check the sum's parity. If it's odd, the square is white, and otherwise it's black.
Time Complexity: O(1), evaluates a simple expression.
Space Complexity: O(1), utilizes constant overhead.
Observing the chessboard, we find that two squares (x_1, y_1) and (x_2, y_2) with the same color satisfy that both x_1 + y_1 and x_2 + y_2 are either odd or even.
Therefore, we can get the corresponding coordinates (x, y) from coordinates. If x + y is odd, the square is white, and we return true; otherwise, we return false.
The time complexity is O(1), and the space complexity is O(1).
Python
Java
C++
Go
TypeScript
Rust
JavaScript
C
| Approach | Complexity |
|---|---|
| Index-Based Calculation | Time Complexity: O(1), since the algorithm performs a constant amount of work. |
| Parity of Coordinates | Time Complexity: O(1), evaluates a simple expression. |
| Pattern Recognition | — |
| Approach | Time | Space | When to Use |
|---|---|---|---|
| Index-Based Calculation | O(1) | O(1) | Clear and explicit conversion from chess notation to numeric coordinates. |
| Parity of Coordinates | O(1) | O(1) | Preferred in interviews; directly uses parity pattern of a chessboard. |
LeetCode-1812.Determine Color of a chess board square • Journey with AI: Unlocked • 1,508 views views
Watch 9 more video solutions →Practice Determine Color of a Chessboard Square with our built-in code editor and test cases.
Practice on FleetCode