[Google Onsite] String Conversion

Given 2 strings s and t, determine if you can convert s into t. The rules are:

You can change 1 letter at a time.
Once you changed a letter you have to change all occurrences of that letter. Example 1:

Input: s = "abca", t = "dced"
Output: true
Explanation: abca ('a' to 'd') -> dbcd ('c' to 'e') -> dbed ('b' to 'c') -> dced
Example 2:

Input: s = "ab", t = "ba"
Output: true
Explanation: ab -> ac -> bc -> ba
Example 3:

Input: s = "abcdefghijklmnopqrstuvwxyz", t = "bcdefghijklmnopqrstuvwxyza"
Output: false
Example 4:

Input: s = "aa", t = "cd"
Output: false
Example 5:

Input: s = "ab", t = "aa"
Output: true
Example 6:

Input: s = "abcdefghijklmnopqrstuvwxyz", t = "bbcdefghijklmnopqrstuvwxyz"
Output: true
Both strings contain only lowercase English letters.




Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.