11. Isomorphic Strings
The problem can be found at the following link: Question Link
My Approach
To determine if two strings are isomorphic,
I create two maps,
mp1
andmp2
, to store the mapping from characters instr1
tostr2
and vice versa.I iterate through both strings simultaneously, updating the mappings.
If at any point, the mapping doesn't hold, I return false.
If the entire iteration completes without any mismatches, the strings are isomorphic.
Time and Auxiliary Space Complexity
Time Complexity:
O(N)
, whereN
is the length of the input strings.Auxiliary Space Complexity:
O(N)
, as we use two unordered maps.
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.
Last updated