Very Simple and Easy Solution | Java | Using single array 🚀
IntuitionThe problem asks if two strings can be made equal by swapping at most one pair of characters in s1. To solve this, we need to check if the strings are
# Intuition
The problem asks if two strings can be made equal by swapping **at most one pair of characters** in `s1`. To solve this, we need to check if the strings are already identical or if a single swap can resolve their differences. If the strings differ by exactly two characters, swapping them should make the strings equal. If there are more than two differences, it's impossible to fix them with just one swap.

# Approach
1. First, check if the lengths of `s1` and `s2` are different; if so, return `false`.
2. Count the frequency of each character in both strings to ensure they contain the same characters.
3. Count the positions where `s1` and `s2` differ.
4. If there are more than two differences, return `false` (since only one swap is allowed). Otherwise, return `true`.

# Complexity
- Time complexity:
*O(n)*, since we iterate through the strings a few times.

- Space complexity:
*O(1)*, as we use a fixed-size array (arr[26]) for character counting.

# Code
```java []
class Solution {
    public boolean areAlmostEqual(String s1, String s2) {
        // If lengths are different, return false
        if(s1.length() != s2.length()) return false;

        // Frequency count for characters in both strings
        int[] arr = new int[26];
        for(int i = 0; i < s1.length(); i++) {
            arr[s1.charAt(i) - 'a']++;  // Increment for s1
            arr[s2.charAt(i) - 'a']--;  // Decrement for s2
        }

        // If character frequencies don't match, return false
        for(int i = 0; i < 26; i++) {
            if(arr[i] != 0) return false;
        }

        // Count mismatched positions
        int count = 0;
        for(int i = 0; i < s1.length(); i++) {
            if(s1.charAt(i) != s2.charAt(i)) count++;
        }

        // If there are more than 2 mismatches, return false
        return count == 2 || count == 0;
    }
}


```
['Array', 'String', 'Counting', 'Java']