Loading...
Loading...
You are given a string s of lowercase English letters and a list of strings pairs. Each element of pairs is a two-character string, such as "ab", meaning the characters a and b are equivalent.
If a and b are equivalent, then b and a are also equivalent. If a and b are equivalent and b and c are equivalent, then a and c are also equivalent too. Every character is equivalent to itself, even one that never appears in pairs.
Return whether s is a palindrome once characters at mirrored positions are compared by equivalence instead of by exact equality.
Note that pairs may contain repeated entries, and both characters of a pair may be the same, such as "aa".
Input: s = "mnop", pairs = ["mp", "no"]
Output: true
Explanation: m and p are equivalent, so position 0 matches position 3. n and o are equivalent, so position 1 matches position 2.
Input: s = "mnop", pairs = ["mp"]
Output: false
Explanation: m and p are equivalent, so position 0 matches position 3. But n at position 1 and o at position 2 are never made equivalent, and n != o, so s is not a palindrome under the equivalence relation.
s.length ≤105pairs.length ≤105s consists of lowercase English letters.pairs is a two-character string of lowercase English letters.