Alternate Vowel and Consonant String
Submissions: 894   Accuracy:

39.24%

  Difficulty: Medium   Marks: 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

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: harshitsidhwa


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.