🔥 Simple and Efficient Java Solution || Well Explained ✅ || Beats 94% memory users
IntuitionThe goal is to determine if two strings s1 and s2 can be made equal by swapping exactly one pair of characters. This means:
The strings must have at mo
# Intuition
The goal is to determine if two strings s1 and s2 can be made equal by swapping exactly one pair of characters. This means:

1. The strings must have at most two mismatched characters.
2. The mismatched characters must be able to swap to match each other.


# Approach
1. Initialize Variables

    -   count: Keeps track of mismatched character positions.
    -   set1 and set2: Store the mismatched characters from s1 and s2.
2. Iterate through s1 and s2

    -   If s1[i] != s2[i], increment count and store mismatched characters in set1 and set2.
    -   If count > 2, return false (more than one swap needed).
3. Final Checks

    -   If count == 2 and both sets are equal, return true (one valid swap exists).
    -   If count == 0, return true (strings are already equal).
    -   Otherwise, return false.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$$O(n)$$
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$$O(1)$$
# Code
```java []
class Solution {
    public boolean areAlmostEqual(String s1, String s2) {
        int count = 0;
        Set<Character> set1 = new HashSet<>();
        Set<Character> set2 = new HashSet<>();

        for (int i = 0; i < s1.length(); i++) {
            char ch1 = s1.charAt(i);
            char ch2 = s2.charAt(i);
            
            if (ch1 != ch2) {
                count++;
                set1.add(ch1);
                set2.add(ch2);
            }
            
            if (count > 2) return false;
        }

        return (count == 2 && set1.equals(set2)) || count == 0;
    }
}

```
['Hash Table', 'String', 'Counting', 'Java']