Word Pattern
easyTime: O(n)Space: O(n)
Signals to notice
check if string follows word-to-pattern mappingbijection between words and pattern charssame as isomorphic strings
Brute force first
Try all mappings — O(n!).
The key insight
Two maps: pattern char → word AND word → pattern char. Check consistency at each position. O(n × m) where m is average word length.
What must stay true
Same as isomorphic strings but with characters and words. The mapping must be bijective — each pattern char maps to exactly one word and vice versa.
Easy way to go wrong
Only checking one direction — 'a b' matching 'cc cc' requires both directions to detect the inconsistency.