Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

53. Isomorphic Strings

EasyDay 16 of 60Strings

Two strings s and t of the same length are isomorphic if you can rename the characters of s to get t. Every occurrence of a character must be renamed to the same character, and two different characters may not be renamed to the same one (a character may map to itself). Return true if s and t are isomorphic.

Example 1
Input: s = "egg", t = "add"
Output: true
e maps to a, g maps to d.
Example 2
Input: s = "foo", t = "bar"
Output: false
o would have to map to both a and r.
Example 3
Input: s = "badc", t = "baba"
Output: false
b and d would both map to b.
Constraints
  • 1 <= s.length <= 5 * 10^4
  • t.length == s.length
  • `s` and `t` contain any valid ASCII characters
Hints
Frequently asked at: Google, Amazon, LinkedIn, Zoho
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min