#3274
Easy Algorithms Check if two chessboard squares have the same color
Math String
72.2% acceptance
Feb 25, 2026
142
5
You are given two strings coordinate1 and coordinate2 (e.g. "a1", "h3").
Return true if they have the same chess board color.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn check_two_chessboards(coordinate1: String, coordinate2: String) -> bool {
let color = |s: &str| -> i32 {
let b = s.as_bytes();
let col = (b[0] - b'a') as i32;
let row = (b[1] - b'1') as i32;
(col + row) % 2
};
color(&coordinate1) == color(&coordinate2)
}
}