Swap Lex Order - CodeSignal
Given a string str and an array of pairs that indicate which indices in the string can be swapped, the function solution(str, pairs) returns the lexicographically largest string that results from doing the allowed swaps. Indices can be swapped any number of times. Example: For str = "abdc" and pairs = [[1, 4], [3, 4]] , the output should be solution(str, pairs) = "dbca" . By swapping the given indices, you get the strings: "cbda", "cbad", "dbac", "dbca". The lexicographically largest string in this list is "dbca". Input/Output: Execution time limit: 4 seconds (py3) str : a string consisting only of lowercase English letters with guaranteed constraints of 1 ≤ str.length ≤ 104 . pairs : an array containing pairs of indices that can be swapped in str (1-based). This means that for each pairs[i] , you can swap elements in str that have the indices pairs[i][0] and pairs[i][1] with guaranteed constraints of 0 ≤ pair