DIY: String Transforms into Another String

Solve the interview question "String Transforms into Another String" in this lesson.

Problem statement

Given two strings of the same length str1 and str2, determine whether you can transform str1 into str2 by doing zero or more conversions.

Note: In one conversion you can convert all occurrences of one character in str1 to any other lowercase English character.

Return true if and only if you can transform str1 into str2.


The input will be two strings. The following is an example input:

inputs = ("aabcc", "ccdee")  


The output will be a Boolean value. The following is an example output:


Coding exercise

Implement the canConvert(str1, str2) function, where str1 is the string that needs to be converted to str2. The function returns true or false depending on whether the conversion is possible.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.