‹ DS&A interview · Socratic
DSA · Hash Table · #92

Isomorphic Strings

Module 54 · difficulty 2/5·30:00starts on first keystroke

Two strings `s` and `t` are **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. Implement `isIsomorphic(s, t)` that returns `true` if `s` and `t` are isomorphic, and `false` otherwise.

Examples
  • s = "egg", t = "add" truee -> a, g -> d (consistent and one-to-one).
  • s = "foo", t = "bar" falseo would need to map to both a and r.
  • s = "badc", t = "baba" falseTwo different source chars (d, c) map to the same target b/a is fine, but here a and c both map to a -> not one-to-one.
Constraints
  • · 1 <= s.length <= 5 * 10^4
  • · t.length == s.length
  • · s and t consist of any valid ASCII characters.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.