-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path4th_December.py
49 lines (39 loc) · 1.13 KB
/
4th_December.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#User function Template for python3
class Solution:
def rearrange(self, S, N):
result = ''
if N == 1:
result = S
else:
v = []
c = []
for i in S:
if i in ['a','e','i','o','u']: v.append(i)
else: c.append(i)
V = len(v)
C = len(c)
v.sort()
c.sort()
if V == 0 or C == 0:
result = -1
elif V == C or V == C+1 :
for i in range(N):
result += v[i//2] if i%2 == 0 else c[i//2]
elif C == V+1 :
for i in range(N):
result += c[i//2] if i%2 == 0 else v[i//2]
else:
result = -1
return result
#{
# Driver Code Starts
#Initial Template for Python 3
if __name__=='__main__':
t=int(input())
for _ in range(t):
N = int(input().strip())
S = input().strip()
ob=Solution()
ans=ob.rearrange(S, N)
print(ans)
# } Driver Code Ends