Easy and Simple Solution | Beginner-friendly | Beats100%🚀
CodeIf you found this solution helpful, please give it an upvote! 🌟✨ It really motivates me to share more solutions like this. 😊👍
Happy coding! 💻🐱‍🏍
IntuitionTh
# Code
```java []
class Solution {
    public boolean areAlmostEqual(String s1, String s2) {
        if(s1.equals(s2)){
            return true;
        }
        int arr[]=new int[2];
        int a=0;
        for(int i=0;i<s1.length();i++){
            if(s1.charAt(i)!=s2.charAt(i)){
                if(a>=2){
                    return false;
                }
                arr[a]=i;
                a++;
            }
        }
        if(a!=2){
            return false;
        }
        return (s1.charAt(arr[0])==s2.charAt(arr[1]) && 
        s1.charAt(arr[1])==s2.charAt(arr[0]));
    }
}
```
**If you found this solution helpful, please give it an upvote! 🌟✨ It really motivates me to share more solutions like this. 😊👍
Happy coding! 💻🐱‍🏍**
<img src="https://assets.leetcode.com/users/images/6e8c623a-1111-4d21-9a5b-54e00e7feabb_1738093236.165277.jpeg" width=250px>
### Intuition
The problem requires checking if two strings can be made equal by swapping exactly one pair of characters.  
- If `s1` is already equal to `s2`, return `true`.  
- Otherwise, find positions where they differ.  
- If they differ at exactly **two positions**, check if swapping the characters at those positions makes them equal.

### Approach
1. If `s1` is already equal to `s2`, return `true`.  
2. Traverse both strings and track indices where they differ.
   - If they differ at more than **two positions**, return `false`.  
3. If there are exactly **two differences**, check if swapping the mismatched characters results in equality.
   - If yes, return `true`, else return `false`.

### Complexity Analysis
- **Time Complexity:** \(O(N)\), where \(N\) is the length of the strings. We traverse the strings once.
- **Space Complexity:** \(O(1)\), as we use only a constant amount of extra space.
['Java']