Strings String basics
127. Isomorphic Strings
You are given two strings s and t. Return true if you can turn s into t by replacing its letters, and
false otherwise. Two such strings are called isomorphic.
The replacing follows two rules. Every copy of a letter is replaced by the same letter. Two different letters are never replaced by the same letter. A letter may also stay as it is.
The letters keep their places, so the letter at index i of s becomes the letter at index i of t.
Example 1
Input: s = "moon", t = "seed"
trueExplanation: m becomes s, both copies of o become e, and n becomes d. No two letters of s share a
replacement.
Example 2
Input: s = "bat", t = "too"
falseExplanation: a and t would both have to become o. Two different letters cannot become the same letter.
Example 3
Input: s = "abab", t = "baba"
trueExplanation: a becomes b and b becomes a. A letter may become a letter that s also uses.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ s.length, t.length ≤ 105sandthold lowercase English letters only.
Clarifying questions
What you would ask an interviewer before writing any code.