left and right of equal length. For every position i, the letters left[i] and right[i] are *interchangeable*. Interchangeability carries through chains: if a can be swapped for b and b for c, then a can be swapped for c too. Every letter is interchangeable with itself.
You are also given a word word. Each of its letters may independently be replaced by any letter interchangeable with it. Return the lexicographically smallest word you can get this way.left="tab", right="kxy", word="bat" → 'bak'
The pairs form groups {t, k}, {a, x} and {b, y}. b stays b, a stays a, and t becomes k, giving bak.
left="cd", right="dz", word="zoo" → 'coo'
c = d and d = z, so c, d and z are interchangeable. z turns into c, and o has no pairs: coo.
left="m", right="m", word="mmm" → 'mmm'
left="tab", right="kxy", word="bat"
'bak'
Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.