Check ~Swapibility in RUBY!
IntuitionWhen I first looked at this problem, I realized that for two strings to be made equal with one swap, they must either:
Already be equal, or
Have exactl
# Intuition
When I first looked at this problem, I realized that for two strings to be made equal with one swap, they must either:
1. Already be equal, or
2. Have exactly two positions where they differ, and swapping those positions in one string would make them equal

# Approach
I broke down the solution into three steps:

1. **Early Return Check**:
   - If strings are already equal, return true immediately

2. **Find Differing Positions**:
   - Iterate through both strings simultaneously
   - Store positions where characters differ

3. **Validate Swap**:
   - Check if exactly 2 positions differ
   - Verify that swapping these positions would make strings equal

# Complexity
- Time complexity: $$O(n)$$
  - Single pass through strings to find differences
  - n is length of strings

- Space complexity: $$O(1)$$
  - Only storing positions of differences
  - Maximum 2 positions stored

# Code
```ruby
# @param {String} s1
# @param {String} s2
# @return {Boolean}
def are_almost_equal(s1, s2)
    return true if s1 == s2
    
    # Find positions where strings differ
    diff_positions = []
    s1.each_char.with_index do |c, i|
        diff_positions << i if c != s2[i]
    end
    
    # Check if exactly 2 positions differ and swapping them makes strings equal
    return false unless diff_positions.length == 2
    i, j = diff_positions
    
    # Check if swapping makes strings equal
    s1[i] == s2[j] && s1[j] == s2[i]
end
```


['Ruby']