InferenceAI

Enter at least two characters to search.

Start free

Same Pattern Words

easyArrays & Strings15 min10 XP

Two strings are isomorphic if the characters of s can be replaced to get t, where each character maps to exactly one character and no two characters map to the same one. Return True if s and t are isomorphic.

Constraints

  • 0≤0 \le len(s) == len(t) ≤5⋅104\le 5 \cdot 10^4

Examples

EXAMPLE WALKTHROUGHisomorphic

A guided view of the published example, not a trace of your code.

INPUT["egg","add"]
TASKsame_pattern_words()
EXPECTED OUTPUTtrue

Start with the input values shown in this example.

Example 1 of 3

Input: s = "egg", t = "add"

Output: true

Explanation: isomorphic

Input: s = "foo", t = "bar"

Output: false

Explanation: o maps twice

Input: s = "paper", t = "title"

Output: true

Explanation: longer

Hint 1

Keep two dictionaries, one in each direction, and check consistency.

Topics

DSAArrays & StringsPython