Check if Two Chessboard Squares Have the Same Color - Problem
You are given two strings, coordinate1 and coordinate2, representing the coordinates of a square on an 8 x 8 chessboard.
Return true if these two squares have the same color and false otherwise.
The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first (indicating its column), and the number second (indicating its row).
Note: On a chessboard, squares alternate between light and dark colors. Square 'a1' is dark, and colors alternate from there.
Input & Output
Example 1 — Adjacent Squares
$
Input:
coordinate1 = "a1", coordinate2 = "c3"
›
Output:
true
💡 Note:
Both squares are dark: a1 (1+1=2, even) and c3 (3+3=6, even) have same parity
Example 2 — Different Colors
$
Input:
coordinate1 = "a1", coordinate2 = "h3"
›
Output:
false
💡 Note:
a1 is dark (1+1=2, even) while h3 is light (8+3=11, odd), different colors
Example 3 — Same Row Different Color
$
Input:
coordinate1 = "a1", coordinate2 = "b1"
›
Output:
false
💡 Note:
Adjacent squares in same row: a1 (sum=2, even) vs b1 (sum=3, odd) have different colors
Constraints
- coordinate1.length == 2
- coordinate2.length == 2
- 'a' ≤ coordinate1[0], coordinate2[0] ≤ 'h'
- '1' ≤ coordinate1[1], coordinate2[1] ≤ '8'
Visualization
Tap to expand
Understanding the Visualization
1
Input Coordinates
Two chess square coordinates like 'a1' and 'c3'
2
Parity Check
Convert to numbers and check if sums have same parity
3
Color Match
Same parity means same color (true), different parity means different colors (false)
Key Takeaway
🎯 Key Insight: Chessboard colors alternate based on coordinate sum parity - same parity means same color
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code