Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Isomorphic Strings

Easy
stringhash-map

Two strings are isomorphic if the characters of s can be replaced (via a consistent one-to-one mapping) to obtain t. Every occurrence of a character must map to the same character, and no two characters may map to the same one.

Input

  • Line 1: string s
  • Line 2: string t (same length)

Output: true or false.

Example 1
Input:
egg
add
Output:
true

e→a, g→d.

Example 2
Input:
foo
bar
Output:
false

o would need to map to both a and r.

Example 3
Input:
badc
baba
Output:
false

b and d would both map to b.

Constraints

  • 1 ≤ s.length = t.length ≤ 5·10^4
  • Printable ASCII characters.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.