![]() |
VOOZH | about |
Given two strings str and str1, the task is to check whether one string can be converted to other by using the following operation:
For example, if str = "abacd" and operation is to change character 'a' to 'k', then the resultant str = "kbkcd"
Examples:
Input: str = "abbcaa"; str1 = "bccdbb"
Output: Yes
Explanation: The mappings of the characters are:
c --> d
b --> c
a --> b
Input: str = "abbc"; str1 = "bcca"
Output: No
Explanation: The mapping of characters are:
a --> b
b --> c
c --> a
Here, due to the presence of a cycle, a specific order cannot be found.
Approach:
Below is the implementation of the above approach.
Yes
Time Complexity: O(N * logN), where N is the length of string s1.
Auxiliary Space: O(N)