1 Pass | Example Walkthrough | No Extra Space | 100% BEATS
IntuitionThe solution checks if two strings can be made equal with at most one swap by tracking the first mismatch and attempting a swap when a second mismatch
### Intuition  
The solution checks if two strings can be made equal with **at most one swap** by tracking the **first mismatch** and attempting a swap when a **second mismatch** is found. The core logic:
1. **0 mismatches**: Already equal ✅  
2. **1 mismatch**: Impossible to fix with one swap ❌  
3. **2 mismatches**: Swap and check if strings become equal 🔄  
4. **>2 mismatches**: Immediately return false 🚫  

---

### Examples  
| Input (s1, s2) | Output | Explanation |  
|----------------|:------:|-------------|  
| `"bank"`, `"kanb"` | ✅ `true` | Swap indices 0 and 3 → `"bank"` |  
| `"ab"`, `"cd"` | ❌ `false` | Two mismatches but invalid swap |  
| `"hello"`, `"hlelo"` | ✅ `true` | Swap indices 2 and 3 → `"hello"` |  
| `"a"`, `"a"` | ✅ `true` | Already identical |  

---

### Code    
```cpp []
class Solution {
public:
    bool areAlmostEqual(string s1, string s2) {
        int x = -1;
        for (int i = 0; i < s1.size(); i++) {
            if (s1[i] != s2[i]) {
                if (x == -1) x = i;
                else {
                    swap(s1[i], s1[x]);
                    return s1 == s2;
                }
            }
        }
        return s1 == s2;
    }
};
```

```java []
class Solution {
    public boolean areAlmostEqual(String s1, String s2) {
        char[] arr = s1.toCharArray();
        int x = -1;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != s2.charAt(i)) {
                if (x == -1) x = i;
                else {
                    arr[i] = arr[x];
                    arr[x] = s2.charAt(i); // Direct swap check
                    return String.valueOf(arr).equals(s2);
                }
            }
        }
        return s1.equals(s2);
    }
}
```

```python []
class Solution:
    def areAlmostEqual(self, s1: str, s2: str) -> bool:
        arr, x = list(s1), -1
        for i in range(len(s1)):
            if arr[i] != s2[i]:
                if x == -1:
                    x = i
                else:
                    arr[i], arr[x] = arr[x], arr[i]
                    return ''.join(arr) == s2
        return s1 == s2
```

```javascript []
var areAlmostEqual = function(s1, s2) {
    let arr = [...s1], x = -1;
    for (let i = 0; i < s1.length; i++) {
        if (arr[i] !== s2[i]) {
            if (x === -1) x = i;
            else {
                [arr[i], arr[x]] = [arr[x], arr[i]];
                return arr.join('') === s2;
            }
        }
    }
    return s1 === s2;
};
```
['Python', 'C++', 'Java', 'JavaScript']