-
Notifications
You must be signed in to change notification settings - Fork 1
/
15th_december.py
46 lines (36 loc) · 1.21 KB
/
15th_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
#User function Template for python3
class Solution:
def BalancedString(self,N):
N_u = N
temp = []
alphab = ""
if N>26:
N_u = N%26
alphab="abcdefghijklmnopqrstuvwxyz"*(N//26)
if(N%2 == 0):
for i in range(N_u//2):
temp.append(chr(97+i))
for i in range(N_u//2,N_u):
temp.append(chr(122-N_u+1+i))
else:
if(sum(list(int(i) for i in str(N)))%2 == 0):
for i in range((N_u+1)//2):
temp.append(chr(97+i))
for i in range((N_u-1)//2+1,N_u):
temp.append(chr(122-N_u+1+i))
else:
for i in range((N_u-1)//2):
temp.append(chr(97+i))
for i in range((N_u+1)//2-1,N_u):
temp.append(chr(122-N_u+1+i))
return alphab+"".join(str(i) for i in temp)
#{
# Driver Code Starts
#Initial Template for Python 3
if __name__=='__main__':
t=int(input())
for _ in range(t):
N=int(input())
ob=Solution()
print(ob.BalancedString(N))
# } Driver Code Ends