This question evaluates string manipulation and combinatorial reasoning skills, focusing on character multisets, permutations, and the implications of a bounded number of swap operations.
You are given two restaurant names represented as strings s and t of equal length (same character set, case-sensitive).
In one operation, you may swap any two characters in s (i.e., pick indices i and j and exchange s[i] and s[j]). You may perform at most 2 swaps.
Return true if you can transform s into exactly t using at most 2 swaps; otherwise return false.
Constraints (reasonable assumptions):
1 <= n = s.length = t.length <= 2e5
Example:
s = "abca"
,
t = "aabc"
->
true
(swap indices 1 and 3 to get "aabc")
s = "abcd"
,
t = "badc"
->
true
(swap (0,1) then swap (2,3))
s = "abcd"
,
t = "abdc"
->
true
(one swap)
s = "abcd"
,
t = "abdd"
->
false
(different multiset of characters)