text of lowercase English letters and a list links, where each link [a, b] is a pair of positions in the string (0-based).
The letters at the two positions of any link may be swapped, as many times as you like and in any order.
Return the lexicographically smallest string you can turn text into using these swaps.text="lkji", links=[[0, 2], [1, 3]] → 'jilk'
Swap positions 0 and 2 ("jkli"), then positions 1 and 3, which gives "jilk".
text="post", links=[[0, 1], [1, 3]] → 'opst'
Positions 0, 1 and 3 are chained together, so their letters p, o, t can be arranged freely as o, p, t. The s at position 2 stays put.
text="ba", links=[] → 'ba'
There are no links, so nothing can move.
text consists of lowercase English letterstext="lkji", links=[[0, 2], [1, 3]]
'jilk'
Run checks the first 3 tests in your browser. Submit checks all 77 tests on the server, hidden ones included.