Isomorphic Strings
Given two strings s and t, return true if they are isomorphic, and false otherwise. Two strings are isomorphic if the characters in s can be replaced to get…
Given two strings `s` and `t`, return `true` if they are isomorphic, and `false` otherwise. Two strings are isomorphic if the characters in `s` can be replaced to get `t`, preserving order. Each character in `s` maps to exactly one character in `t`, and no two distinct characters in `s` may map to the same character in `t` (bijective mapping). A character may map to itself. Indexing is **0-based**. **Example:** `s = "egg"`, `t = "add"`. Mapping: `e → a`, `g → d`. Every pair is consistent, so the answer is `true`.
- `1 <= s.length, t.length <= 5 × 10^4` - `s` and `t` consist of any valid ASCII characters. - Strings of different lengths cannot be isomorphic.
Example 1: input s = "egg", t = "add"; output true. 'e' maps to 'a' and 'g' maps to 'd'. The mapping is consistent and bijective.
Example 2: input s = "foo", t = "bar"; output false. 'o' would need to map to both 'a' and 'r', violating the one-to-one rule.
Example 3: input s = "paper", t = "title"; output true. p→t, a→i, e→l, r→e. Each character maps uniquely — the mapping is bijective.
Category: Strings. Topic: strings. Difficulty: Easy. Patterns: hashing.