Determine Color of a Chessboard Square

easy string math

Problem

You are given a two-character string coordinates representing a chessboard square, where the first character is a column 'a'..'h' and the second is a row '1'..'8'. Return true if the square is white and false if it is black.

Inputcoordinates = "c7"
Outputfalse
Column c = 2, row 7 = 6; 2 + 6 = 8 is even → black.

def square_is_white(coordinates):
    col = ord(coordinates[0]) - ord("a")
    row = int(coordinates[1]) - 1
    return (col + row) % 2 == 1
function squareIsWhite(coordinates) {
  const col = coordinates.charCodeAt(0) - 97;
  const row = Number(coordinates[1]) - 1;
  return (col + row) % 2 === 1;
}
class Solution {
    public boolean squareIsWhite(String coordinates) {
        int col = coordinates.charAt(0) - 'a';
        int row = coordinates.charAt(1) - '1';
        return (col + row) % 2 == 1;
    }
}
bool squareIsWhite(string coordinates) {
    int col = coordinates[0] - 'a';
    int row = coordinates[1] - '1';
    return (col + row) % 2 == 1;
}
Time: O(1) Space: O(1)