Magicsheet logo

Determine Color of a Chessboard Square

Easy
74.3%
Updated 6/1/2025

Asked by 2 Companies

Determine Color of a Chessboard Square

What is this problem about?

The Determine Color of a Chessboard Square coding problem gives you a coordinate string representing a square on an 8imes88 imes 8 chessboard (e.g., "a1", "h3"). You need to return true if the square is white and false if it is black. On a standard chessboard, the bottom-left square "a1" is black, and the colors alternate both horizontally and vertically.

Why is this asked in interviews?

J.P. Morgan and other financial firms use this "Easy" question to test basic mathematical intuition and string parsing. It evaluations whether you can map characters ('a'-'h') and digits ('1'-'8') to a numeric coordinate system and whether you can identify the parity pattern that governs alternating colors. It’s a test of "Coordinate Mapping" and "Modulo Arithmetic."

Algorithmic pattern used

This problem uses Parity Logic and Math. A square at (x,y)(x, y) is white if the sum of its coordinates (x+y)(x + y) is odd, and black if the sum is even (assuming 0-indexed coordinates where (0,0) is black).

  1. Convert the character (e.g., 'a') to an integer (0-7).
  2. Convert the digit (e.g., '1') to an integer (0-7).
  3. Calculate (charValue + digitValue) % 2.

Example explanation

Coordinate: "a1"

  1. 'a' o o 0, '1' o o 0. Sum = 0. 0 % 2 == 0 (Black). Result: false. Coordinate: "b1"
  2. 'b' o o 1, '1' o o 0. Sum = 1. 1 % 2 == 1 (White). Result: true. Coordinate: "h3"
  3. 'h' o o 7, '3' o o 2. Sum = 9. 9 % 2 == 1 (White). Result: true.

Common mistakes candidates make

  • Hard-coding: Trying to create a full 8imes88 imes 8 2D array to store the colors. While it works, it's unnecessary and less elegant than a mathematical solution.
  • Indexing Errors: Confusion between 1-based indexing from the string and 0-based indexing used in calculations.
  • Misinterpreting "White": Getting the logic flipped (thinking even is white).

Interview preparation tip

Whenever you encounter a grid with alternating patterns (like a chessboard), the answer almost always involves (row + col) % 2. This is a universal trick for "checkerboard" logic.

Similar Questions