#1812
Easy Algorithms Determine color of a chessboard square
Math String
79.8% acceptance
Feb 25, 2026
901
24
You are given coordinates, a string that represents the coordinates of a square of the chessboard.
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.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn square_is_white(coordinates: String) -> bool {
let bytes = coordinates.as_bytes();
let col = (bytes[0] - b'a') as i32;
let row = (bytes[1] - b'1') as i32;
(col + row) % 2 == 1
}
}