pairs, where each pair [x, y] means the words x and y are interchangeable. Synonymy is transitive: if x can stand in for y and y for z, then x can stand in for z too.
You are also given sentence, a sequence of words separated by single spaces. Any word of the sentence that has synonyms may be replaced by any word from its group (or kept as is); all other words stay unchanged.
Return every distinct sentence obtainable this way, sorted lexicographically as strings.pairs=[["quick", "fast"], ["fast", "rapid"]], sentence="a quick fix" → ['a fast fix', 'a quick fix', 'a rapid fix']
quick, fast and rapid form one synonym group, so there are three sentences, listed in alphabetical order.
pairs=[["big", "huge"], ["old", "ancient"]], sentence="big old house" → ['big ancient house', 'big old house', 'huge ancient house', 'huge old house']
Two independent swaps give 2 × 2 = 4 variants.
pairs=[], sentence="nothing to swap" → ['nothing to swap']
sentence has 1 to 20 words separated by single spacespairs=[["quick", "fast"], ["fast", "rapid"]], sentence="a quick fix"
['a fast fix', 'a quick fix', 'a rapid fix']
Run checks the first 3 tests in your browser. Submit checks all 126 tests on the server, hidden ones included.