Problem · Hash Table

Isomorphic Strings

Learn this problem
EasyRemitly logoRemitlyFULLTIMEONSITE INTERVIEW

Problem statement

Given two strings s and t, determine whether they are isomorphic.

The strings are isomorphic when every character in s can be replaced consistently to produce t without changing character positions. Every occurrence of one character must map to the same character, and two different characters from s cannot map to the same character in t. A character may map to itself.

Function

isIsomorphic(s: String, t: String) → boolean

Examples

Example 1

s = "egg"t = "add"return = true

Map 'e' to 'a' and 'g' to 'd'. Applying those substitutions consistently produces t.

Example 2

s = "f11"t = "b23"return = false

The character '1' would need to map to both '2' and '3', so no consistent mapping exists.

Example 3

s = "paper"t = "title"return = true

The repeated-character pattern is identical in both strings, and each character has one distinct position-preserving mapping.

Constraints

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

More Remitly problems

drafts saved locally
public boolean isIsomorphic(String s, String t) {
  // Write your code here.
}
s"egg"
t"add"
expectedtrue
checking account