Saturday, October 12, 2013

[Microsoft Interview] String Manipulation

Given a string say "ABCD". Now create a new string with duplicates of each character in the original string and append the reverse of the same string (with duplicates) excluding the last character. 

First iteration: AABBCCCCBBAA 
[ABC three types of chars; Here c is the last char.Ignore duplicates after the last char c] 

Second iteration: AABBBBAA 

[here b is the last char] 

Third iteration: AAAA 
[no second char left]

No comments:

Post a Comment