Recently I came across a google interview question. The question is as follows:
You are given two strings, P and Q consisting of characters 'a' and 'b'.
At any given point you can perform two kind of operations on the string P:
- You either append character
atoP. - You append character
bto P and then you reverseP.
You can perform any of these operations any number of times.
You have to tell me whether it is possible for P to be equal to Q, after performing such operations?
An example:
- P =
a, Q =baa. this will returntrue, - P =
b, Q =ab, this will returnfalse
Can someone tell me, how I can approach this question or such questions? Because I am having difficulty in grasping a way on how to proceed?
Comments (18)

