---
# System prepended metadata

title: LC 3274. Check if Two Chessboard Squares Have the Same Color
tags: [easy, leedcode, c++]

---

# LC 3274. Check if Two Chessboard Squares Have the Same Color

### [Problem link](https://leetcode.com/problems/check-if-two-chessboard-squares-have-the-same-color/)

###### tags: `leedcode` `easy` `c++`

You are given two strings, <code>coordinate1</code> and <code>coordinate2</code>, representing the coordinates of a square on an <code>8 x 8</code> chessboard.

Below is the chessboard for reference.

<img alt="" src="https://assets.leetcode.com/uploads/2024/07/17/screenshot-2021-02-20-at-22159-pm.png" style="width: 400px; height: 396px;" />

Return <code>true</code> if these two squares have the same color and <code>false</code> 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).

**Example 1:** 

<div class="example-block">
Input: <span class="example-io">coordinate1 = "a1", coordinate2 = "c3"

Output: <span class="example-io">true

Explanation:

Both squares are black.

**Example 2:** 

<div class="example-block">
Input: <span class="example-io">coordinate1 = "a1", coordinate2 = "h3"

Output: <span class="example-io">false

Explanation:

Square <code>"a1"</code> is black and <code>"h3"</code> is white.


 **Constraints:** 

- <code>coordinate1.length == coordinate2.length == 2</code>
- <code>'a' <= coordinate1[0], coordinate2[0] <= 'h'</code>
- <code>'1' <= coordinate1[1], coordinate2[1] <= '8'</code>

## Solution 1
#### C++
```cpp=
class Solution {
public:
    bool checkTwoChessboards(string coordinate1, string coordinate2) {
        int tmp = coordinate1[0] - 'a' + coordinate1[1] - '0';
        int tmp2 = coordinate2[0] - 'a' + coordinate2[1] - '0';
        return tmp % 2 == tmp2 % 2;
    }
};
```

>### Complexity
>|             | Time Complexity | Space Complexity |
>| ----------- | --------------- | ---------------- |
>| Solution 1  | O(1)            | O(1)             |

## Note
x
