String Pattern Mapping

Problem Given two strings (or a pattern and a string of tokens), determine whether they follow a consistent one-to-one character/token mapping — every character in the first must map to exactly one counterpart in the second, and vice versa (bijective mapping).

Input / Output

  • Input: two strings s and t (or pattern + word list).
  • Output: boolean — true if a consistent bijective mapping exists.

Constraints

  • Lengths up to 10^5; the mapping must hold in both directions.
  • A length mismatch is an immediate false.

Example

  • s = "egg", t = "add" → true (e→a, g→d)
  • s = "foo", t = "bar" → false (o would map to both a and r)
  • s = "badc", t = "baba" → false (fails the reverse direction: b and d would both map to a's counterpart)
asked …
LeaderboardSalaryAccount