This is an interview questions asked from me.
An input string is made up of only a, b and c. You have to reduce the string to minimum possible length. Reducing criteria is:
if ab or ba comes together, it can be replaced by c
if bc or cb comes together, it can be replaced by a
if ac or ca comes together, it can be replaced by b
For example,
abcbca --> abaca --> caca --> cba --> cc or aa
abcbca --> ccbca --> caca --> same as above
I could not even think of any proper logic. I started thinking in terms of odd and even place occurrence, but it did not help. Please help me in buildinga logic for it
Thanks