DIVGOLD - Editorial

Anyone wanna help me find out counter example for my code to the problem?
http://www.codechef.com/viewsolution/6574368

you are correct my approach would give HOH .
but correct answer clearly seems to be HHO.

i can be done in o(n).

lets take an example -abaaazzaa

alright now lets calculate frequency of all letters.(do it in ha table or something)
a-6,b-1,z-2

alright now , we store the leftmost a’s position that is 8(i=0 based index).
so its obvious that at index 1 , we need to replace b with a, which can be done in two ways.
1st way- we take the last a and inject it before b.
2nd way- we keep shifting b towards the end until there is a letter which is bigger than b.
the key obs is that , the answer has to be one of it , there is no other option, so what we do is buid both the string seperatly (both are o(n)).
now s1=aabaaazza and s2=aaaabzza
so the answer is s2.
if there is any cornor case im missing , pls lemme know :slight_smile:

@amitpandeykgp i solved this question using C++ stl ( insert and erase function).I just want to know whether complexity of insert and erase is O(1) or O(n)?? Here is my solution :
https://www.codechef.com/viewsolution/10649315

So, overall Complexity is O(n^3) or O(n^2) ??

all test cases given above are working then also i am getting a wrong ans
https://www.codechef.com/viewsolution/10858733

help!

can anyone provide me some test cases

i think my approach is o(n)
link:https://www.codechef.com/viewsolution/14979205
with two steps :
first insert at first mismatch
second: remove at first mismatch
and than compare both solution and print that which is lesser