DIVGOLD getting wa

i am getting wa in DIVGOLD, below is my code.
Please tell me where i am wrong.

link of my solution.

Try this test case:

1

4

ABAA

Your soution is giving “AABA” while the correct answer if “AAAB” if we move “B” to last position.

1 Like

i got where i am wrong.

1 Like