Saturday, November 19, 2011

Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'. What is the smallest string which can result by applying this operation repeatedly?


4 comments :

Jaldeep said...

answer :: 1

Unknown said...

@Jaideep ..Can You Explain the algorothm or logic on the basis u answered ?

Anonymous said...

Jaldeep's answer is wrong:

try sequence:

abbbc

I believe correct answer is first comment on:

http://www.careercup.com/question?id=11534280

Unknown said...

@anon ..answer suggested by ashish is pretty much correct , also small correction pointed out by me , a guy czpete425 while anon given correctness of algorithm , dats pretty good explanation :)