Alternate Vowel and Consonant String
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).

Examples:

Input : mango
Output : gamon
It could be arranged in other ways too, like
manog, etc., but gamon is lexicographically
smallest.

Input:
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.

Output:
For each test print the rearranged string on the new line.

Constraints:
1<=T<=100
1<=N<=103

Example:
Input:

2
9
aeroplane
11
mississippi
Output:
alanepero
-1

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.