title: Algorithm exercise
body: <p>I'm working on this algorithm exercise but I don't understand completely the formulation. Here is the exercise:</p>
  
  <blockquote>
    <p>Given a string str and array of pairs that indicates which indices in
    the string can be swapped, return the lexicographically largest string
    that results from doing the allowed swaps. You can swap indices any
    number of times.</p>
    
    <p>Example</p>
    
    <p>For str = "abdc" and pairs = [[1, 4], [3, 4]], the output should be
    swapLexOrder(str, pairs) = "dbca".</p>
    
    <p>By swapping the given indices, you get the strings: "cbda", "cbad",
    "dbac", "dbca". The lexicographically largest string in this list is
    "dbca".</p>
    
    <p>Input/Output</p>
    
    <p>[execution time limit] 4 seconds (js)</p>
    
    <p>[input] string str</p>
    
    <p>A string consisting only of lowercase English letters.</p>
    
    <p>Guaranteed constraints: 1 ≤ str.length ≤ 104.</p>
    
    <p>[input] array.array.integer pairs</p>
    
    <p>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].</p>
    
    <p>Guaranteed constraints: 0 ≤ pairs.length ≤ 5000, pairs[i].length = 2.</p>
    
    <p>[output] string</p>
  </blockquote>
  
  <p>My question is, why "abcd" is not a posible answer (just swapping index 3 and 4 on the original string "abdc")? The example says </p>
  
  <blockquote>
    <p>By swapping the given indices, you get the strings: "cbda", "cbad",
    "dbac", "dbca". The lexicographically largest string in this list is
    "dbca"</p>
  </blockquote>
  
  <p>I understand that even if "abcd" is a possible answer "dbca" is lexicographically largest so the answer is the same. But if I don't understand why "abcd" is not a possible answer I think I'm misunderstanding the task</p>