Watch 10 video solutions for Determine Color of a Chessboard Square, a easy level problem involving Math, String. This walkthrough by Journey with AI: Unlocked has 1,508 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
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.
| 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. |