← All problems

Word Pattern (bijection check)

Easy hash mapsstrings LeetCode ↗
Given a pattern string and a space-separated word string, check whether the pattern bijectively maps to the words — e.g. pattern 'abba' matches 'dog cat cat dog' but not 'dog cat cat fish'.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(n)

Common pitfalls

  • Checking only one direction
  • Length mismatch ignored

Your solution

Log in to save your code and track progress.