Tap here to switch tabs
Problem
Submissions

Problem: Sentence Similarity

Try to solve the Sentence Similarity problem.

Statement

Given two arrays of strings sentence1 and sentence2, and an array of string pairs similarPairs where similarPairs[i] = [x_i, y_i] represents that the words x_i and y_i are similar, determine if sentence1 and sentence2 are similar.

Two sentences are similar if:

  • They have the same length.

  • For each index i, the word sentence1[i] is similar to sentence2[i].

Two words w1 and w2 are similar if:

  • w1 == w2, or

  • The pair [w1, w2] or [w2, w1] exists in similarPairs.

Return true if sentence1 and sentence2 are similar, and false otherwise.

Note: The similarity relation is not transitive. If w1 is similar to w2 and w2 is similar to w3, it does not imply that w1 and w3 are similar.

Constraints:

  • 1≤1 \leq sentence1.length, sentence2.length ≤1000\leq 1000

  • 1≤1 \leq sentence1[i].length, sentence2[i].length ≤20\leq 20

  • sentence1[i] and sentence2[i] consist of English letters.

  • 0≤0 \leq similarPairs.length ≤1000\leq 1000

  • similarPairs[i].length =2= 2

  • 1≤1 \leq x_i.length, y_i.length ≤20\leq 20

  • x_i and y_i consist of lowercase and uppercase English letters.

  • All the pairs (x_i, y_i) are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sentence Similarity

Try to solve the Sentence Similarity problem.

Statement

Given two arrays of strings sentence1 and sentence2, and an array of string pairs similarPairs where similarPairs[i] = [x_i, y_i] represents that the words x_i and y_i are similar, determine if sentence1 and sentence2 are similar.

Two sentences are similar if:

  • They have the same length.

  • For each index i, the word sentence1[i] is similar to sentence2[i].

Two words w1 and w2 are similar if:

  • w1 == w2, or

  • The pair [w1, w2] or [w2, w1] exists in similarPairs.

Return true if sentence1 and sentence2 are similar, and false otherwise.

Note: The similarity relation is not transitive. If w1 is similar to w2 and w2 is similar to w3, it does not imply that w1 and w3 are similar.

Constraints:

  • 1≤1 \leq sentence1.length, sentence2.length ≤1000\leq 1000

  • 1≤1 \leq sentence1[i].length, sentence2[i].length ≤20\leq 20

  • sentence1[i] and sentence2[i] consist of English letters.

  • 0≤0 \leq similarPairs.length ≤1000\leq 1000

  • similarPairs[i].length =2= 2

  • 1≤1 \leq x_i.length, y_i.length ≤20\leq 20

  • x_i and y_i consist of lowercase and uppercase English letters.

  • All the pairs (x_i, y_i) are distinct.