Medium Accuracy: 42.38% Submissions: 1756 Points: 4
Given a string str. Your task is to write a program that takes string str as input and rearrange characters of the given string such that the vowels and consonants occupy alternate position and the string so formed should be lexicographically (alphabetically) smallest.
If string can not be rearranged in desired way, print “-1” (without quotes).
Input : mango
Output : gamon
It could be arranged in other ways too, like
manog, etc., but gamon is lexicographically
First line of the input contains an integer T, denoting the number of test cases. Then T test case follows. First line of each test case contains an integer N, denoting the size of the string. Next line contains the string str.
For each test print the rearranged string on the new line.