Determine Color of a Chessboard Square - Problem

You are given coordinates, a string that represents the coordinates of a square on a chessboard.

A chessboard is an 8x8 grid where squares alternate between white and black colors. The bottom-left square a1 is a dark (black) square.

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.

Input & Output

Example 1 — Corner Square
$ Input: coordinates = "a1"
Output: false
💡 Note: Square a1 is at column 1, row 1. Sum = 1 + 1 = 2 (even), so it's black. Return false.
Example 2 — White Square
$ Input: coordinates = "h3"
Output: true
💡 Note: Square h3 is at column 8, row 3. Sum = 8 + 3 = 11 (odd), so it's white. Return true.
Example 3 — Adjacent Square
$ Input: coordinates = "c7"
Output: false
💡 Note: Square c7 is at column 3, row 7. Sum = 3 + 7 = 10 (even), so it's black. Return false.

Constraints

  • coordinates.length == 2
  • coordinates[0] is a letter from 'a' to 'h'
  • coordinates[1] is a digit from '1' to '8'

Visualization

Tap to expand
Determine Chessboard Square ColorINPUTcoordinates = "h3"Chess square notationPROCESSh → 8, row = 3Sum = 8 + 3 = 1111 is odd → whiteOUTPUTtrueSquare is whiteChessboard Pattern Rule:Even sum (col + row) → Black squareOdd sum (col + row) → White square
Understanding the Visualization
1
Input
Chessboard coordinates as string (e.g., "a1")
2
Process
Convert to numbers and check sum parity
3
Output
Boolean indicating if square is white
Key Takeaway
🎯 Key Insight: The sum of column number and row number determines the square color through parity check
Asked in
Google 15 Microsoft 12 Amazon 8
25.0K Views
Medium Frequency
~5 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen