first and second and a list of synonym pairs synonyms, where a pair [x, y] means the words x and y can replace each other (in either direction).
The phrases are equivalent if they have the same number of words and, at every position i, the words first[i] and second[i] are either identical or form a synonym pair from the list. Synonyms do not chain: pairs [a, b] and [b, c] do not make a and c synonyms.
Return true if the phrases are equivalent and false otherwise.first=['quick', 'brown', 'fox'], second=['fast', 'brown', 'fox'], synonyms=[['fast', 'quick']] → True
"quick" and "fast" are synonyms (a pair works both ways), and the other words match exactly.
first=['big', 'house'], second=['huge', 'home'], synonyms=[['big', 'large'], ['large', 'huge'], ['house', 'home']] → False
"big" matches "large" and "large" matches "huge", but similarity does not chain, so "big" and "huge" are not synonyms.
first=['hello'], second=['hello', 'there'], synonyms=[] → False
The phrases have different numbers of words, so they cannot match.
first.length, second.length ≤ 10⁴synonyms.length ≤ 10⁴synonyms[i].length == 2 and all pairs are distinctfirst=['quick', 'brown', 'fox'], second=['fast', 'brown', 'fox'], synonyms=[['fast', 'quick']]
True
Run checks the first 3 tests in your browser. Submit checks all 122 tests on the server, hidden ones included.