🔢✨✅ Check If Digits Become Equal After Operations 🔁 | C++ 🧮 | Brute Force Approach 💪
🧠 Intuition
The goal is to check whether a given string of digits can be reduced to a 2-digit string where both digits are the same. At each step, you generate
# 🧠 Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- The goal is to check whether a given string of digits can be reduced to a 2-digit string where both digits are the same. At each step, you generate a new string by summing adjacent pairs of digits (mod 10) until the length of the string becomes 2.
# 📌 Approach
<!-- Describe your approach to solving the problem. -->
**1. Edge Case Check:**
- If the input string s already has a length of 2, we directly compare the two digits.

**2. Iterate Until Length is 2:**
- Create a new string by summing every pair of consecutive digits.
- Store the last digit of each sum using modulo 10.
- Update s with the new string.

**3. Final Check:** 
- Return true if the two remaining digits are the same; otherwise, return false.
# ⏳ Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
    - Each iteration reduces the string length by 1. Starting with length 𝑛, there are 𝑂(𝑛) iterations.
    - Within each iteration, constructing the new string takes 𝑂(𝑛) time.
    - Therefore, the overall complexity is 𝑂(𝑛^2).
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
    - We use extra space for the new string in each iteration, which is proportional to the input size 𝑂(𝑛).
    - Thus, the space complexity is 𝑂(𝑛).
# Code
```cpp []
class Solution {
public:
    bool hasSameDigits(string s) {
        while (s.length() > 2) {
            string str = "";
            for (int i = 0; i < s.length() - 1; i++) {
                int sum = (s[i] - '0') + (s[i + 1] - '0');
                str += to_string(sum % 10);
            }
            s = str;
        }
        return s[0] == s[1];
    }
};
```
['C++']