A translator maps symbol patterns to words. Given a symbol pattern and a sentence, verify if the sentence follows the exact structure of the pattern (each symbol maps to exactly one word and vice versa).
Explanation: Step 1: Split the pattern into unique characters: ['x', 'y']. Step 2: Split the sentence into words: ['sun', 'moon', 'moon', 'sun']. Step 3: Compare the length of unique characters in the pattern and sentence. Since 'x' and 'y' are unique characters in the pattern, but 'sun' and 'moon' are not unique words in the sentence, the lengths do not match. Step 4: Return false because the sentence does not follow the exact structure of the pattern.
Explanation: Step 1: Split the pattern into unique characters: ['a', 'b']. Step 2: Split the sentence into words: ['dog', 'cat', 'cat', 'dog']. Step 3: Compare the length of unique characters in the pattern and sentence. Since 'a' and 'b' are unique characters in the pattern, but 'dog' and 'cat' are not unique words in the sentence, the lengths do not match. Step 4: Return false because the sentence does not follow the exact structure of the pattern.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak