6. Isomorphic Strings
Two strings are isomorphic if the characters in s can be replaced to get t.
Solution: (hashmaps)
Approach:
Two string must be of same length.
Map each character of string s
with a character of string t.
And the character of the string t
should not be mapped with any other char of string s.
But this takes an Time Complexity: O(n*n) as we need to search if a char is mapped earlier or not.
Efficient Approach: (using hashset and hashmap)
Time Complexity: O(n)
Last updated