Practice/Google/Leetcode 737. Sentence Similarity II
CodingMust
You are given two arrays of words, words1 and words2, both of the same length. You are also given a list of word pairs where each pair [a, b] indicates that word a and word b are considered similar to each other.
The similarity relationship is transitive: if word a is similar to word b, and word b is similar to word c, then word a is also similar to word c. Additionally, every word is similar to itself.
Determine whether the two arrays represent equivalent sequences. Two arrays are equivalent if for every index i, the word at words1[i] is either identical to or similar to the word at words2[i].
Return true if the arrays are equivalent, and false otherwise.
true only if all corresponding positions contain equivalent wordsExample 1:
` Input: words1 = ["wonderful", "day"] words2 = ["great", "day"] pairs = [["wonderful", "great"]]
Output: true
Explanation:
Example 2:
` Input: words1 = ["fast", "car"] words2 = ["quick", "vehicle"] pairs = [["fast", "rapid"], ["rapid", "quick"], ["car", "auto"]]
Output: false
Explanation:
Example 3:
` Input: words1 = ["one"] words2 = ["one"] pairs = []
Output: true
Explanation: The words are identical at the only position `