Isomorphic Strings

Easy#205two maps

You get two strings of the same length, s and t. Find out whether the letters of s can be replaced to get t: one letter always turns into the same letter, and two different letters never turn into the same one. Our example: "stone" and "ladle" — no: both s and n would have to become l.

input
s, t: strings of the same length.
returns
true if replacing letters of s gives t: every occurrence of a letter by the same letter, no two letters by the same one, a letter may stay itself; otherwise false.
constraints
  • 1 ≤ s.length ≤ 2000
  • t.length == s.length
  • s, t: lowercase English letters
our 11 tests keep to them
examples
Open a test in the tests panel: it shows the input and the expected answer.
/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
function isIsomorphic(s, t) {

}
Ctrl ↵
format
reset

saved in this browser

11 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more hash map problems

Pattern “Hash map” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.