Google India screening round Interview question | L3 | Reject

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-10-26Added By Anonymous
Source: Link

Company: Google
Role: L3
Interview Stage: Phone Screen
Location: India
Year: unknown

Original Post Content:

Q. Given two strings of equal length made up of 'x', 'y', and 'z', with no consecutive characters the same, determine the minimum number of operations needed to transform the first string into the second. In one operation, you can change any character in the first string, ensuring no consecutive characters become identical.

for ex:
str1: zxyz
str2: zyxz

result: 6

ex #2:
str1: xyzyzyxyzx
str2: xzyzyzyxzy

result: 15

ex #3:
str1: xyxyxyxyxy
str2: xzyxyxzyxz

result: 13

ex #4:
str1: xyxyzyzyxy
str2: zyzyxzyzyz

result: 9

ex #5
str1: xzxyxyzyzyxyzx
str2: zyzyxzyzyzyxzy

res: 20

I tried BFS, but it will not work. The expected time complexity was linear, O(length of the string).

Comments