734. Sentence Similarity
Approach 1: Memoised pairs
The first level solution is to create a memoised dictionary that keeps track of the words and their neighbours in a set. Then we can just iterate through the original arrays, to see if they have some common words b/w their sets, and if they don't we can return False
Time Complexity: O(max(len(pairs), len(words1)))
Space Complexity: O(len(pairs)*len(words)) (Since we do not need to store all the synonyms)
Last updated