305. Isomorphic Strings
Easy
Bidirectional Mapping
Hashing
Problem
Given two strings s and t, determine whether they are isomorphic. Every occurrence of a character in s must map to the same character in t, and two different characters in s cannot map to the same character in t.
Examples
Example 1
Input: "egg", "add"
Output: true
Example 2
Input: "foo", "bar"
Output: false
Example 3
Input: "paper", "title"
Output: true
Constraints
� 1 <= s.length <= 50000
� t.length == s.length
Hints
?? A mapping in only one direction is not sufficient.
?? Track s-to-t and t-to-s mappings simultaneously.
Expected Complexity
Time: O(n)
Space: O(k)
Follow-up
Can you solve it using arrays of last-seen positions rather than explicit maps?
Practice Notes
Attempts: 0
Time spent: 0min
Hints used: 0
JavaScript
00:00
Loading...
Case 1
Case 2
Case 3
Input
"egg", "add"Expected
true