Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Check if two strings are isomorphic

Determine whether two strings are isomorphic by ensuring a one-to-one mapping between characters.

Python practice16 minHashing & SetsIntermediateLast updated March 26, 2026

Problem statement

Two strings s and t are isomorphic if characters in s can be replaced to get t, with a one-to-one mapping (no two characters map to the same character unless identical). Given two strings s and t, determine if they are isomorphic. Return True if they are, otherwise False.

Task

Use hashing (dictionaries) to validate a bijective mapping from characters of one string to another.

Examples

Basic mapping

Input

s = 'egg', t = 'add'

Output

True

e -> a, g -> d, consistent mapping exists and is one-to-one.

Input format

Two strings s and t.

Output format

Boolean value True if s and t are isomorphic, otherwise False.

Constraints

0 <= len(s), len(t) <= 10^5. Strings contain ASCII characters. Must run in O(n) time and O(1) additional space for mappings (alphabet-size bound).

Samples

Sample 1

Input

s = 'paper', t = 'title'

Output

True

p->t, a->i, p mapped consistently, e->l, r->e. Mapping is bijective.