14 · Hashing & Prefix Sums

#205 Isomorphic Strings

Easysolve on LeetCode ↗

frequently reported atLinkedInBloombergAmazonGoogle

the problem

In plain words

Two strings of the same length are isomorphic if you can turn s into t by replacing characters: every occurrence of a character must become the same character, and no two different characters may become the same one. A character may stay itself. Return whether s and t are isomorphic.

in s = "egg", t = "add"

out true

e → a and g → d.

in s = "foo", t = "bar"

out false

o would have to become both a and r.

in s = "paper", t = "title"

out true

  • 1 ≤ s.length ≤ 5·10⁴
  • t.length == s.length
  • s and t contain any valid ASCII characters

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #290
      Word Pattern
      Easyin Hashing
    2. #49
      Group Anagrams
      Mediumin Arrays & Strings