Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-133

Isomorphic Strings

Problem

Return True if characters of s can be replaced to obtain t while preserving order, with a one-to-one character mapping.

Maintain mappings in both directions and fail if a character maps inconsistently either way. Strings of different lengths are never isomorphic.

Hint

The backward map prevents two different source characters mapping to the same target.

Test cases

case 1
in: ["egg","add"]
expected: true
case 2
in: ["foo","bar"]
expected: false
case 3
in: ["paper","title"]
expected: true
case 4
in: ["ab","aa"]
expected: false
case 5
in: ["",""]
expected: true
Starter codePython
def is_isomorphic(s, t):
    # Your code here
    pass

5 test cases · run your code against them in the editor