Easy  Beats 100%✅✅ || O(n) || Single pass || C++
ApproachThe approach involves finding the indices where s1 and s2 differ. If there are exactly two mismatched indices, swapping the characters at those indices
![image.png](https://assets.leetcode.com/users/images/e97c8474-1399-40cb-ab13-bd7ddde3f618_1738750230.400874.png)

## Approach
The approach involves finding the indices where `s1` and `s2` differ. If there are exactly two mismatched indices, swapping the characters at those indices in `s2` should make `s1` and `s2` equal. If there is only one mismatch or more than two mismatches, return `false`.

## Complexity
- **Time complexity:**
  - The solution iterates through the strings once, so the time complexity is **O(n)**.

- **Space complexity:**
  - Only a few integer variables are used (`diff1`, `diff2`), so the space complexity is **O(1)**.

## Code
```cpp
class Solution {
public:
    bool areAlmostEqual(string s1, string s2) {
        // Storing the two miss-matching indexes
        int diff1 = -1, diff2 = -1;
        for (int i = 0; i < s1.length(); i++) {
            if (s1[i] != s2[i] && diff1 == -1) {
                diff1 = i;
            } else if (s1[i] != s2[i] && diff2 == -1) {
                diff2 = i;
            }
        }
        // If only one index found return false
        if (diff1 != -1 && diff2 == -1) return false;
        // If more than one index needs swapping
        if (diff1 != -1) swap(s2[diff1], s2[diff2]);
        // Comparing the string after swapping
        return s1 == s2;
    }
};
```


['C++']