Smallest string from allowed swaps
You get a string s and a list pairs of positions [i, j]. You may swap the letters at positions i and j of any listed pair, as many times as you like and in any order. Return the alphabetically smallest string you can reach.
s uses lowercase a–z and has at least one letter; every position is a valid index of s. A pair may repeat or have i == j. Aim for near-linear time plus sorting.
Besides the tests, one large input (2,000 letters, 2,499 pairs) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
smallest_after_swaps("tsyb", [[0,3],[1,2]])→"bsyt"smallest_after_swaps("golf", [[0,1],[1,2],[2,3]])→"fglo"smallest_after_swaps("hello", [])→"hello"