Menu
CoddyTech

Isomorphic Strings

EasyHashingpython iconjava iconcpp iconc iconjs icon+10

Two strings are isomorphic when you can rename the characters of the first to get the second. Every copy of a character gets the same new name, two different characters never get the same name, and a character may keep its own. For two strings s and t of the same length, return true when they are isomorphic and false when they are not.

Function

isIsomorphic(s: string, t: string) → boolean
sstring
the string to rename, letters and digits
tstring
the string to reach, the same length as s
Returnsboolean
true if a one-to-one renaming of the characters of s gives t

Constraints

  • 1 ≤ s.length ≤ 2 × 104
  • t.length == s.length
  • s and t contain only English letters and digits. Upper and lower case are different characters.

Examples

Input
s = "noon"t = "deed"
Output
true
Explanation
Rename n to d and o to e. Every position agrees with that renaming, and the two letters get different names.
challenge icon

Follow-up

Given a list of words, can you group together the ones that are isomorphic to each other without comparing every pair of words?

Reset code
def isIsomorphic(s, t):
    # Write code here

Test #1

Test #2

Test #3

Arguments

s = "noon"
t = "deed"

Expected Output

true