Skip to content
Decoder

Isomorphic Strings

Easy

Problem

Two strings s and t are isomorphic if you can replace characters in s to get t, where every occurrence of a character is replaced by the same character, and **no two different characters map to the same character**. A character may map to itself. Return true if s and t are isomorphic.

Example 1

Input
s = "egg", t = "add"
Output
true
Why
e→a, g→d

Example 2

Input
s = "foo", t = "bar"
Output
false
Why
o would need to become both a and r

Example 3

Input
s = "badc", t = "baba"
Output
false
Why
b and d would both become b

Constraints

  • 1 <= s.length <= 5 * 10^4
  • t.length == s.length
  • s and t consist of any valid ASCII characters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.