Swift💯Union Find
Union-Find approach (accepted answer)\n\nclass Solution {\n    func smallestEquivalentString(_ s1: String, _ s2: String, _ baseStr: String) -> String {\n       
**Union-Find approach (accepted answer)**\n```\nclass Solution {\n    func smallestEquivalentString(_ s1: String, _ s2: String, _ baseStr: String) -> String {\n        var groups = Dictionary(uniqueKeysWithValues: "abcdefghijklmnopqrstuvwxyz".map {($0,$0)})\n        \n        func find(_ x: Character) -> Character {\n            if x != groups[x] { groups[x] = find(groups[x]!) }  // path compression, if needed\n            return groups[x]!\n        }\n        \n        for (a, b) in zip(s1, s2) { \n            let (x,y) = (find(a), find(b))\n            groups[max(x,y)] = min(x,y) // make union of letter pairs from `s1` and `s2`, lowest value ranked highest\n        }\n        \n        return String(baseStr.map(find)) \n    }\n}\n```
['Swift']