Mercedes-Benz | SDE-2
Anonymous User
2544

magical strings:
given a string of only uppercase english alphabets, create a string of max length which only contains either 'A' or 'B' in a lexicographically order. new string should have all A's in one sequence and B's in another sequence (or reverse). return "Impossible" if no such string exists.
NOTE: there was one condition i.e., for a given i (where 1 <= s[i] < s.length), all characters before i will be 'A' and after i will be 'B' or vice-versa.

1 <= s.length <= 10^5

e.g. 
1. s = "ABDFGAB"
   answer = "AAB"
2. s = "WXTY"
   answer = "Impossible"
3. s = "BA"
   answer = "BA"
4. s = "B"
   answer = "B"
5. s = "ABBABAA"
   answer = "BBBAA"

help is very much appreciated. just to be specific, the intention was not to get the answer and submit my solution (actually I've already completed the challenge earlier, I just wanted to see other people's approach). also this challenge has been ended.

Comments (3)