Efficient Digit Compression and Comparison in Strings
🔥 IntuitionThe goal is to repeatedly reduce the string by summing adjacent digits and appending the result modulo 10 until the string length becomes 2 or less.

### 🔥 **Intuition**
<!-- Describe your first thoughts on how to solve this problem. -->
The goal is to repeatedly **reduce the string** by summing adjacent digits and appending the result modulo `10` until the string length becomes **2 or less**.  
- If the resulting string has exactly **two equal digits**, return `true`.  
- Otherwise, return `false`.  

💡 **Key Insight:**  
- The process mimics **digit compression**, where the string is progressively shortened by combining adjacent digits.

---

### 🚀 **Approach**
<!-- Describe your approach to solving the problem. -->
1. **Iteration Until Length ≤ 2:**
   - Use a `while` loop that continues until the string length is **2 or less**.
2. **Combining Adjacent Digits:**
   - Iterate over the string with a `for` loop.
   - Extract adjacent digits using `charAt()` and convert them to integers using `Integer.parseInt()`.
   - Sum the adjacent digits and take the result modulo `10`.
   - Append the result to a `StringBuilder`.
3. **Update the String:**
   - After each iteration, update the string (`s`) with the newly formed string (`sb.toString()`).
4. **Final Comparison:**
   - When the length is reduced to **2**, check if the two digits are the same.
   - Return `true` if they are equal, otherwise `false`.

---

### 🔥 **Complexity Analysis**

- **Time Complexity:**  
\[O(n \log n)\]  
   - Each iteration reduces the string length roughly by **half**, making the process logarithmic.
   - In each iteration, you process the entire string of length `n`, making it `O(n)` per iteration.
   - Therefore, the overall complexity is **`O(n log n)`**.

- **Space Complexity:**  
\[O(n)\]  
   - You create a `StringBuilder` during each iteration, which holds the compressed digits.
   - In the worst case, the space complexity is proportional to the size of the input string, hence **`O(n)`**.

---
# Code
```java []
class Solution {
    public boolean hasSameDigits(String s) {
        while (s.length() > 2) {
            StringBuilder sb = new StringBuilder();
            for (int i = 1; i < s.length(); i++) {
                int num = (Integer.parseInt(Character.toString(s.charAt(i - 1))) + Integer.parseInt(Character.toString(s.charAt(i)))) % 10;
                sb.append(Integer.toString(num));
            }
            s = sb.toString();
        }
        return s.charAt(0) == s.charAt(1);
    }
}
```
['Java']