Back to DSA sheet

Isomorphic Strings

EasyArrays

Two strings are isomorphic if the characters of s can be replaced to get t, with a consistent one-to-one mapping: each character maps to exactly one character and no two characters map to the same one. Order is preserved.

Input format (stdin): the first line is s, the second line is t. Output true or false.

Examples
Input: egg add
Output: true
e->a, g->d is consistent and one-to-one.
Input: foo bar
Output: false
o would map to both a and r.
Constraints
  • 1 <= |s| <= 5*10^4
  • |s| == |t|
Sheets
NeetCode 250
isomorphic-strings.cpp3 sample tests
Loading editor
Test results

Run the sample tests to check your solution against expected output.

Custom input (stdin)
Output

Run your code to see its output.