Beats 100% ✅ | Most Optimal Solution 🏆| C++🚀
Intuition 🔍The problem requires checking whether two strings can be made equal by swapping at most one pair of characters in one of the strings.
If the strings
# Intuition 🔍
The problem requires checking whether two strings can be made equal by swapping at most one pair of characters in one of the strings.

1. If the strings are already equal, return true.
1. If they differ at more than two positions, swapping won’t help, so return false.
1. If they differ at exactly two positions, swapping those two characters in one string should make them equal.

# Approach 📊

1. Compare Characters:
    - Iterate through both strings and find the indices where they differ.
    - Store these indices in a vector idx.

2. Handle Edge Cases:
    - If s1 == s2, return true (they are already equal).
    - If there are more than two differences, return false (cannot fix with one swap).
    - If there is only one difference, return false (one swap cannot fix it).

3. Perform the Swap:
    - If there are exactly two differing positions, swap those characters in s2.
    - After the swap, compare s1 and s2. If they are equal, return true; otherwise, return false.

# Complexity 📈
- Time complexity: O(n)

- Space complexity: O(1)

# Code
```cpp []
class Solution {
public:
    bool areAlmostEqual(string s1, string s2) {
        int n=s1.size();
        vector<int> idx;
        for(int i=0;i<n;i++){
            if(s1[i] != s2[i] && idx.size()<2){
                idx.push_back(i);
            }
        }
        if(idx.size()>1){
            swap(s2[idx[0]], s2[idx[1]]);
        }
        if(s1 == s2){
            return true;
        }
        return false;
    }
};
```
['C++']