Adobe wants to play a game. He is given a number N. He has to create a alphabetical string in lower case from that number and tell whether the string is palindrome or not. a = 0 , b = 1….. and so on.  For eg : If the number is 61 the substring “gb” will be printed till 7 (6+1) characters i.e. “gbgbgbg” and check if palindrome or not. Adobe is weak in concepts of palindrome and strings, help him in winning the game.
Note: No number will start with zero. Consider alphabets ' a to j ' only i.e. single digit numbers from 0 to 9.
Example 1:
Ã¢â¬â¹Input : N = 61
Output : YES
Explanation:
N = 61 the substring “gb” will be 
printed till 7 (6+1) characters i.e. 
“gbgbgbg” and it is palindrome. return 
true.
Ã¢â¬â¹Example 2:
Input : N = 1998 
Output :  NO 
 
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function pallan() that takes an integer (N), and return true if the string is a palindrome otherwise return false if not. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).
Constraints:
1 ≤ N ≤ 10^{7}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Mathematics

Starter code: #User function Template for python3



def pallan (n) : 

    #Complete the function



Solutions:
def pallan(n):
	d = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	s = str(n)
	s1 = ''
	sum = 0
	for i in s:
		s1 += d[int(i)]
		sum += int(i)
	strs = ''
	if sum % len(s) == 0:
		strs = s1 * (sum // len(s))
	if sum % len(s) != 0:
		strs = s1 * (sum // len(s))
		rem = sum % len(s)
		if rem > len(s):
			strs += s
			strs += s1[:rem - len(s)]
		else:
			strs += s1[:rem]
	if strs == strs[::-1]:
		return True
	else:
		return False


def pallan(n):
	al = 'abcdefghij'
	a = list(str(n))
	p = []
	s = 0
	sr = ''
	for i in a:
		s += int(i)
		p.append(al[int(i)])
	ss = s
	while s > 0:
		sr += ''.join(p)
		s = s - len(p)
	sr = sr[:ss]
	if sr == sr[::-1]:
		return 1
	else:
		return 0


def pallan(n):
	b = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
	number = str(n)
	substr = ''
	sum = 0
	if number[0] == '0':
		return False
	for i in range(0, len(number)):
		substr += b[int(number[i])]
		sum += int(number[i])
	mainstr = ''
	d = len(substr)
	for i in range(0, sum):
		mainstr += substr[i % d]
	if mainstr[::-1] == mainstr:
		return True
	else:
		return False


def pallan(n):
	n = str(n)
	ll = list(n)
	lis = list(map(int, ll))
	s = sum(lis)
	temp = ''
	for i in n:
		temp += chr(int(i) + 97)
	ss = temp
	temp *= s // len(n)
	temp += ss[:s % len(n)]
	return temp == temp[::-1]


def pallan(n):
	sets = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	string = ''
	strng = str(n)
	for i in range(len(strng)):
		string += sets[int(strng[i])]
	count1 = len(string)
	count = 0
	for i in range(len(strng)):
		count += int(strng[i])
	reminder = count % count1
	pre_string = string * (count // count1)
	for i in range(reminder):
		pre_string = pre_string + string[i]
	final_string = pre_string
	if final_string == final_string[::-1]:
		return True
	else:
		return False


import math

def pallan(n):
	l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
	s = ''
	c = str(n)
	(k, j, i) = (0, 0, 0)
	while i < len(c):
		if int(c[i]) == l.index(l[j]) and j < len(l):
			s += l[j]
			k += int(c[i])
			i += 1
			j = -1
		j += 1
	s = list(s)
	v = ''
	i = 0
	while k != 0:
		k -= 1
		v += s[i]
		i += 1
		if i >= len(s):
			i = 0
	if v == v[::-1]:
		return True
	return False


def pallan(n):
	a = p = k = ''
	sum = 0
	d = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	for i in str(n):
		a += d[int(i)]
		sum += int(i)
	p = a * sum
	k = p[:sum]
	if k == k[::-1]:
		return True
	return False


def pallan(n):
	d = {'0': 'a', '1': 'b', '2': 'c', '3': 'd', '4': 'e', '5': 'f', '6': 'g', '7': 'h', '8': 'h', '9': 'i'}
	number = str(n)
	value = ''
	s = 0
	for i in number:
		s += int(i)
		value += d[i]
	newvalue = value * s
	real = ''
	for i in range(s):
		real += newvalue[i]
	if real == real[::-1]:
		return True
	else:
		return False


def pallan(n):
	num = str(n)
	output = ''
	i = 0
	for char in num:
		i += int(char)
		output += chr(int(char) + 97)
	while len(output) < i:
		output += output
	output = output[:i]
	return output == output[::-1]


def pallan(n):
	n = str(n)
	l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
	s = ''
	x = 0
	for i in n:
		s = s + str(l[int(i)])
		x = x + int(i)
	res = ''
	c = 0
	for i in range(x):
		if c >= len(s):
			c = 0
		res = res + s[c]
		c = c + 1
	if res == res[::-1]:
		return True
	return False


def pallan(n):
	dic = dict()
	dic[0] = 'a'
	dic[1] = 'b'
	dic[2] = 'c'
	dic[3] = 'd'
	dic[4] = 'e'
	dic[5] = 'f'
	dic[6] = 'g'
	dic[7] = 'h'
	dic[8] = 'i'
	dic[9] = 'j'
	a = str(n)
	ans = ''
	Z = 0
	z1 = 0
	for i in a:
		Z += int(i)
		z1 += 1
		ans += dic[int(i)]
	m = Z // z1 + 1
	sub = ans * m
	sub = sub[:Z]
	s = 0
	e = Z - 1
	return sub == sub[::-1]


def pallan(n):
	a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
	s = ''
	c = 0
	while n > 0:
		rem = n % 10
		c += rem
		s += a[rem]
		n //= 10
	rs = s[::-1]
	if c <= len(rs):
		k = rs[:c]
		if k == k[::-1]:
			return True
		return False
	elif c & 1 == 0:
		p = rs * c
		pp = p[0:c]
		if pp == pp[::-1]:
			return True
		return False
	else:
		p = rs * c
		pp = p[0:c]
		if pp == pp[::-1]:
			return True
		return False


def checkPalin(s):
	if s == '':
		return True
	if len(s) == 1:
		return True
	for i in range(int(len(s) / 2)):
		if s[i] != s[-(i + 1)]:
			return False
	return True

def pallan(n):
	d = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	count = 0
	s = ''
	while n > 0:
		lastDigit = n % 10
		count += lastDigit
		s = d[lastDigit] + s
		n = int(n / 10)
	string = ''
	for i in range(count):
		ind = i % len(s)
		string += s[ind]
	return checkPalin(string)


def pallan(n):
	word = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
	res = ''
	mark = 0
	while n > 0:
		temp = n % 10
		mark += temp
		res += word[temp]
		n = n // 10
	if mark == 1:
		return True
	res = res[::-1]
	rem = mark % len(res)
	res += res * (mark // len(res) - 1)
	i = 0
	while i < rem:
		res += res[i]
		i += 1
	rev = res[::-1]
	if rev == res:
		return True
	else:
		return False


def pallan(n):
	lis = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
	k = []
	final = []
	f = n
	while n != 0:
		rem = n % 10
		k.append(rem)
		n = n // 10
	kis = []
	for i in k[::-1]:
		kis.append(lis[i])
	if f < 11:
		return True
	m = sum(k)
	d = m // len(kis)
	for i in range(d):
		final.extend(kis)
	c = m % len(kis)
	if c > 0:
		for i in range(c):
			final.append(kis[i])
	o = len(final) - 1
	for i in range(len(final)):
		if final[i] != final[o]:
			return False
		o -= 1
	return True


from math import floor, log10

def getDigitCount(n):
	num = abs(n)
	digits = floor(log10(num))
	return digits

def createString(string, num):
	stringIndex = 0
	temp = ''
	for index in range(num):
		temp += string[stringIndex]
		stringIndex += 1
		if stringIndex == len(string):
			stringIndex = 0
	return temp

def getStringFromNumber(n, digits):
	map = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	digitCount = digits
	string = ''
	temp = n
	sum = 0
	while digitCount >= 0:
		divisior = 10 ** digitCount
		quo = temp // divisior
		sum += quo
		if map[quo]:
			string += map[quo]
		else:
			return -1
		temp = temp - quo * divisior
		digitCount -= 1
	return createString(string, sum)

def pallan(n):
	digits = getDigitCount(n)
	string = getStringFromNumber(n, digits)
	if string[0] != string[-1]:
		return False
	elif string != string[::-1]:
		return False
	else:
		return True


def ifpal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True

def pallan(n):
	s = str(n)
	sums = 0
	s2 = ''
	for i in range(len(s)):
		sums += int(s[i])
	while len(s2) <= sums:
		s2 += s
	s2 = s2[:sums]
	return ifpal(s2)


def pallan(n):
	dict = {'0': 'a', '1': 'b', '2': 'c', '3': 'd', '4': 'e', '5': 'f', '6': 'g', '7': 'h', '8': 'i', '9': 'j'}
	number = str(n)
	sum = 0
	map_value = ''
	for element in number:
		sum += int(element)
		map_value += dict[element]
	new_map_value = map_value * sum
	result = ''
	for i in range(sum):
		result += new_map_value[i]
	if result == result[::-1]:
		return True
	else:
		return False


def pallan(n):
	dict = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	result = ''
	count = 0
	total_length = 0
	for num in str(n):
		int_n = int(num)
		result += dict[int_n]
		total_length += int_n
	count = total_length // len(result)
	num_res = result * count
	num_res += result[0:total_length - len(num_res)]
	rev_num_res = num_res[::-1]
	return True if num_res == rev_num_res else False


def pallan(n):
	mdict = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	nstr = str(n)
	res = ''
	mcount = 0
	total_length = 0
	for num in nstr:
		int_n = int(num)
		res += mdict[int_n]
		total_length += int_n
	mcount = total_length // len(res)
	mres = res * mcount
	mres += res[0:total_length - len(mres)]
	rev_mres = mres[::-1]
	return True if mres == rev_mres else False


def pallan(n):
	s = str(n)
	arr = list(map(int, s))
	l = len(s)
	count = sum(arr)
	rem = count % l
	div = count // l
	res = ''
	for i in range(1, div + 1):
		res = res + s
	for j in range(rem):
		res += s[j]
	if res == res[::-1]:
		return True
	return False


def pallan(n):
	s = ''
	add = 0
	for i in str(n):
		s += chr(int(i) + 97)
		add += int(i)
	while len(s) < add:
		s += s
	for i in range(int(add / 2)):
		if s[i] != s[add - i - 1]:
			return False
	return True


def pallan(n):
	lst = str(n)
	temp = ''
	total = 0
	for i in lst:
		total += int(i)
		temp += chr(97 + int(i))
	temp = temp * total
	new = temp[:total]
	rev = new[::-1]
	if rev == new:
		return True
	return False


def pallan(n):
	m = {}
	for i in range(10):
		m[str(i)] = chr(97 + i)
	g = len(n)
	s = 0
	for i in n:
		s += int(i)
	i = 0
	t = ''
	while len(t) != s:
		t += m[n[i]]
		i = (i + 1) % g
	return t == t[::-1]


def pallan(n):
	ls = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	n = str(n)
	ans = ''
	summ = 0
	count = 0
	for i in n:
		N = int(i)
		ans += ls[N]
		summ += N
	count = summ // len(ans)
	res = ans * count
	res += ans[0:summ - len(res)]
	if res == res[::-1]:
		return True
	else:
		return False


def pallan(n):
	d = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	nstr = str(n)
	nsum = sum([int(s) for s in nstr])
	alpha = ''.join([d[int(s)] for s in nstr])
	alphastr = alpha * (nsum // len(alpha)) + alpha[:nsum % len(alpha)]
	if alphastr[:] == alphastr[::-1]:
		return True
	return False
for _ in range(0, int(input())):
	n = int(input())
	ans = pallan(n)
	if ans == True:
		print('YES')
	else:
		print('NO')


def pallan(n):
	char_count = 0
	alpha = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j', 10: 'k', 11: 'l', 12: 'm', 13: 'n', 14: 'o', 15: 'p', 16: 'q', 17: 'r', 18: 's', 19: 't', 20: 'u', 21: 'v', 22: 'w', 23: 'x', 24: 'y', 25: 'z'}
	N = str(n)
	string = ''
	for c in N:
		char_count += int(c)
		string += alpha[int(c)]
	q = char_count // len(N)
	r = char_count % len(N)
	string = string * q + string[0:r]
	if string == string[::-1]:
		return True
	return False
for _ in range(0, int(input())):
	n = int(input())
	ans = pallan(n)
	if ans == True:
		print('YES')
	else:
		print('NO')


def pallan(n):
	str = ''
	sum = 0
	while n > 0:
		d = n % 10
		str = str + chr(65 + 32 + d)
		sum = sum + d
		n = n // 10
	str = str[::-1]
	str2 = str * (sum // len(str))
	difference = sum - len(str2)
	str2 = str2 + str2[0:difference]
	reverse_str2 = str2[::-1]
	if reverse_str2 == str2:
		return True
	else:
		return False


def pallan(n):
	s = 'abcdefghij'
	l = ''
	N = str(n)
	cnt = 0
	sum = 0
	for i in N:
		x = int(i)
		sum += x
		l += s[x]
	cnt = sum // len(l)
	ll = l * cnt
	ll += l[:sum - len(ll)]
	lr = ll[::-1]
	if ll == lr:
		return True
	else:
		return False


def pallan(n):
	p = str(n)
	p = list(p)
	s = ''
	su = 0
	for i in p:
		h = int(i)
		su = su + h
		h = h + 97
		s = s + chr(h)
	st = ''
	c = 0
	while su > 0:
		st = st + s[c]
		c = c + 1
		if c == len(s):
			c = 0
		su = su - 1
	k = st[::-1]
	if st == k:
		return 1
	return 0


def pallan(n):
	name_str = str(n)
	sum_n = 0
	arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	num_str = ''
	for i in name_str:
		sum_n += int(i)
		num_str += arr[int(i)]
	num_str *= sum_n
	num_str = num_str[:sum_n]
	if num_str == num_str[::-1]:
		return True
	return False


def pallan(n):
	n1 = 0
	s = 0
	s1 = ''
	while n != 0:
		s = n % 10
		n1 += s
		n = n // 10
		s1 = chr(s) + s1
	s1 = s1 * (n1 // len(s1)) + s1[0:n1 % len(s1)]
	if s1 == s1[n - 1::-1]:
		return True
	return False


def pallan(n):
	x = ''
	s = 0
	for i in str(n):
		x = x + chr(ord(i) + 49)
		s += int(i)
	st = x * (s // len(x))
	if len(st) % s == 0:
		if st == st[::-1]:
			return True
		else:
			return False
	else:
		if s > len(st):
			l = s % len(st)
			st = st + x[:l]
		if st == st[::-1]:
			return True
		else:
			return False


def pallan(n):
	n = str(n)
	x = list(map(int, n))
	l = ''
	y = []
	for i in x:
		y.append(chr(97 + i))
	y = ''.join(y)
	while len(l) <= sum(x):
		l = l + y
	l = l[:sum(x)]
	if l == l[::-1]:
		return True
	else:
		return False


def pallan(n):
	x = 'abcdefghij'
	n = str(n)
	c = ''
	s = 0
	for i in n:
		c = c + x[int(i)]
		s = s + int(i)
	d = ''
	while len(d) < s:
		if len(d) + len(c) > s:
			break
		d = d + c
	if len(d) != s:
		for i in range(s - len(d)):
			d = d + c[i]
	if d == d[::-1]:
		return True
	return False


import math

def pallan(n):
	listOfInteger = list(str(n))
	sumOfList = 0
	series = ''
	palindromeToCheck = ''
	for x in listOfInteger:
		series += chr(int(x) + 97)
		sumOfList += int(x)
	timesToIterate = math.floor(sumOfList / len(series))
	for x in range(timesToIterate):
		palindromeToCheck += series
	leftOver = sumOfList - len(palindromeToCheck)
	palindromeToCheck += series[:leftOver]
	if len(palindromeToCheck) % 2 == 0:
		firstHalf = palindromeToCheck[:math.floor(len(palindromeToCheck) / 2)]
		secondHalf = palindromeToCheck[math.floor(len(palindromeToCheck) / 2):][::-1]
	else:
		firstHalf = palindromeToCheck[:math.floor(len(palindromeToCheck) / 2)]
		secondHalf = palindromeToCheck[math.floor(len(palindromeToCheck) / 2) + 1:][::-1]
	if firstHalf == secondHalf:
		return True
	else:
		return False


def pallan(n):
	list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	t = str(n)
	sum1 = 0
	str1 = ''
	for i in t:
		str1 += list1[int(i)]
		sum1 += int(i)
	t = str1 * sum1
	list1 = [i for i in t]
	temp = list1[:sum1]
	result = ''
	for ele in temp:
		result += ele
	if result == result[::-1]:
		return True
	else:
		return False


def pallan(n):
	l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
	st = ''
	c = n
	sum = 0
	while c > 0:
		p = c % 10
		sum = sum + p
		st = st + l[p]
		c = c // 10
	st = st[::-1]
	st = st * sum
	st = st[:sum]
	st1 = st[::-1]
	if st == st1:
		return True
	else:
		return False


def pallan(n):
	mydict = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f', 6: 'g', 7: 'h', 8: 'i', 9: 'j'}
	num = [int(i) for i in str(n)]
	letter = [mydict[i] for i in num]
	joint = ''.join(letter)
	if sum(num) % len(joint) == 0:
		pattern = joint * sum(num)
	else:
		x = joint * (sum(num) + sum(num) % len(joint))
		pattern = x[:sum(num)]
	if pattern == pattern[::-1]:
		return True
	return False


def pallan(n):
	n = str(n)
	x = 0
	s = ''
	for i in n:
		x += int(i)
		s += chr(int(i) + 97)
	s = s * x
	s = s[:x]
	if s == s[::-1]:
		return True
	return False


def pallan(n):
	x = str(n)
	s = ''
	n = 0
	for i in x:
		s += chr(int(i) + ord('A'))
		n += int(i)
	p = n % len(x)
	n = n // len(x)
	s = s * n
	s += s[0:p]
	rev = s[-1::-1]
	if s == rev:
		return True
	return False


def pallan(n):
	st = ''
	l = []
	while n > 0:
		rem = n % 10
		l.append(rem)
		n = n // 10
	l = l[::-1]
	s = sum(l)
	for i in l:
		st += chr(97 + i)
	div = s // len(st)
	rem = s % len(st)
	st = st * div
	st = st + st[:rem]
	if st == st[::-1]:
		return True
	return False