easy +10 pts

Isomorphic Strings Check

Determine if two strings have a one-to-one character mapping.

Two strings `s` and `t` are called **isomorphic** if the characters in `s` can be replaced to get `t`. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. Write a function `is_isomorphic(s: str, t: str) -> bool` that returns `True` if the two strings are isomorphic and `False` otherwise. Assume the strings only contain lowercase letters. Both strings will have the same length.

Constraints

- `1 <= len(s) == len(t) <= 10^5` - Strings contain only lowercase English letters. - Time: O(n) where n is the length of the strings. - Space: O(1) since there are at most 26 distinct characters.

Example

```python
>>> is_isomorphic("egg", "add")
True
>>> is_isomorphic("foo", "bar")
False
>>> is_isomorphic("paper", "title")
True
>>> is_isomorphic("ab", "aa")
False
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Track the mapping from characters in `s` to characters in `t` and also the reverse mapping to ensure one-to-one.
If you see a character in `s` already mapped to a different character in `t`, return False.
Alternatively, use a dictionary that maps each character to its first occurrence index and compare the resulting lists.
Since only lowercase letters are used, arrays of size 26 can be used for O(1) space.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.