Jarvis is weak in computing palindromes for Alphanumeric characters.
While Ironman is busy fighting Thanos, he needs to activate sonic punch but Jarvis is stuck in computing palindromes.
You are given a string S containing alphanumeric characters. Find out whether the string is a palindrome or not.
If you are unable to solve it then it may result in the death of Iron Man.
Example 1:
Ã¢â¬â¹Input : S = "I am :IronnorI Ma, i"
Output : YES
Explanation:
Ignore all the symbol and whitespaces S = "IamIronnorIMai".
Now, Check for pallandrome ignoring uppercase and lowercase
english letter.
Ã¢â¬â¹Example 2:
Input : S = Ab?/Ba 
Output :  YES 
 
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 saveIronman() that takes an string (ch), and return the true if the string is a palindrome and false if the string is not a palindrome. The driver code takes care of the printing.
Expected Time Complexity: O(N). where N is the length of the string
Expected Auxiliary Space: O(1).
Constraints:
1 ≤ |S| ≤ 100000
Note: Consider alphabets and numbers only for palindrome check. Ignore symbols and whitespaces.

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3

def saveIronman (s) : 
    #Complete the function


Solutions:
def saveIronman(s):
	s = s.lower()
	l = []
	for i in s:
		if i.isalnum():
			l.append(i)
	sl = ''.join(l)
	if sl == sl[::-1]:
		return True
	else:
		return False


def saveIronman(s):
	ans = []
	for x in s:
		if x.isalpha() or x.isnumeric():
			ans.append(x.lower())
	return ans[::1] == ans[::-1]


def saveIronman(s):
	a = ''
	for i in s:
		if i.isalpha() or i.isnumeric():
			a = a + i.upper()
	b = a[::-1]
	return a == b


from re import findall

def saveIronman(s):
	t = findall('[A-Za-z0-9]', s)
	n = len(t)
	mp = n / 2 if n % 2 == 0 else (n + 1) / 2
	mp = int(mp)
	for i in range(mp):
		if t[i].lower() != t[n - i - 1].lower():
			return False
	return True


def saveIronman(s):
	s = ''.join((c.lower() for c in s if c.isalnum()))
	return s == s[::-1]


def saveIronman(s):
	s = ''.join((e for e in s if e.isalnum())).lower()
	return s == s[::-1]


def saveIronman(s):
	s1 = ''
	s2 = 'abcdefghijklmnopqrstuvwxyz'
	s3 = '12334567890'
	for i in s:
		if i.lower() in s2 or i in s3:
			s1 += i
	i = 0
	j = len(s1) - 1
	while i < j:
		if s1[i].lower() != s1[j].lower():
			return False
		i += 1
		j -= 1
	return True


def saveIronman(s):
	l = []
	for i in s:
		if i.isalpha() or i.isnumeric():
			l.append(i.lower())
	return l[:] == l[::-1]


import re

def saveIronman(S):
	z = S.upper()
	cl = re.sub('[^\\w\\s]+', '', z)
	rever = cl[::-1]
	cl = ''.join(cl.split())
	rever = ''.join(rever.split())
	if cl == rever:
		return True
	return False


def saveIronman(s):
	string = s.lower()
	new_str = ''
	for i in string:
		if i.isalpha() or i.isdigit():
			new_str += i
	return new_str == new_str[::-1]


def saveIronman(s):
	res = ''
	for i in s:
		if i >= 'A' and i <= 'Z' or (i >= 'a' and i <= 'z') or (i >= '0' and i <= '9'):
			res += i
	r = res.lower()
	count = 0
	i = 0
	j = len(r) - 1
	while i <= j:
		if r[i] == r[j]:
			i += 1
			j -= 1
		else:
			count = 1
			break
	if count == 0:
		return True
	else:
		return False


import string

def saveIronman(s):
	s = s.lower()
	lista = list(string.ascii_lowercase)
	l = len(s)
	b = ''
	for a in s:
		if a in lista or (ord(a) >= ord('0') and ord(a) <= ord('9')):
			b += a
	for i in range(len(b)):
		if b[i] != b[len(b) - 1 - i]:
			return False
	return True


def saveIronman(s):
	s1 = ''
	for i in range(len(s)):
		if s[i].isalpha() or s[i].isnumeric():
			s1 += s[i].lower()
	if s1 == s1[::-1]:
		return True
	else:
		return False


def saveIronman(s):
	only_alpha = ''
	for char in s:
		if char.isalpha() or char.isdigit():
			only_alpha += char
	S = only_alpha.lower()
	if S == S[::-1]:
		return True
	else:
		return False


def saveIronman(s):
	s1 = ''
	for i in s:
		if i.isalnum():
			s1 += i
	s1 = s1.lower()
	if s1 == s1[::-1]:
		return True
	return False


def saveIronman(s):
	x = ''
	for i in s:
		if i.isalnum():
			x += i.lower()
	re = x[::-1]
	if x == re:
		return True
	return False


def saveIronman(s):
	lst = []
	str1 = ''
	for i in s:
		if i.isalnum():
			lst.append(i)
	str1 = str1.join(lst)
	str1 = str1.lower()
	if str1 == str1[::-1]:
		return True


def saveIronman(s):
	i = 0
	j = len(s) - 1
	while i <= j:
		while i < len(s) and (not s[i].isalnum()):
			i += 1
		while j >= 0 and (not s[j].isalnum()):
			j -= 1
		if s[i].upper() != s[j].upper():
			return False
		i += 1
		j -= 1
	return True


def saveIronman(s):
	l = []
	for i in s:
		if i.isalpha() or i.isdigit():
			l.append(i.lower())
	k = l[::-1]
	if k == l:
		return True
	else:
		return False


def saveIronman(s):
	st = []
	for x in s:
		if x.isalpha() or x.isnumeric():
			st.append(x.lower())
	if st == st[::-1]:
		return 1
	else:
		return 0


def saveIronman(s):
	li_clean_str = []
	for text in s:
		if text.isalpha() or text.isnumeric():
			li_clean_str.append(text.lower())
	clean_str = ''.join(li_clean_str)
	l = 0
	r = len(clean_str) - 1
	while l < r:
		if clean_str[l] != clean_str[r]:
			pass
			return False
		l += 1
		r -= 1
	return True


def saveIronman(s):
	li_clean_str = []
	for text in s:
		if text.isalpha() or text.isnumeric():
			li_clean_str.append(text.lower())
	clean_str = ''.join(li_clean_str)
	return clean_str == clean_str[::-1]


def saveIronman(s):
	s1 = ''
	for ch in s:
		if ch.isalpha() or ch.isdigit():
			s1 += ch
	s1 = s1.lower()
	if s1 == s1[::-1]:
		return True
	return False


def saveIronman(s):
	str1 = ''
	for i in s:
		if i.isalnum():
			if i in '0123456789':
				str1 += i
			else:
				i = i.lower()
				str1 += i
	if str1 == str1[::-1]:
		return True
	return False


def saveIronman(s):
	string = ''
	for i in s:
		if 'A' <= i <= 'Z' or 'a' <= i <= 'z':
			string += i.lower()
		if '0' <= i <= '9':
			string += i
	if string == string[::-1]:
		return True
	return False


def saveIronman(s):
	a = ''
	for c in s:
		if 65 <= ord(c) <= 90 or 97 <= ord(c) <= 122 or 48 <= ord(c) <= 57:
			a += c
	a = a.lower()
	if a == a[::-1]:
		return 1
	else:
		return 0


def saveIronman(s):
	m = ''
	for i in s.upper():
		if i >= 'A' and i <= 'Z':
			m += i
		elif i >= '0' and i <= '9':
			m += i
	k = m[-1::-1]
	if k == m:
		return True
	else:
		return False


def saveIronman(s):
	a = ''
	for i in s:
		if 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122 or 48 <= ord(i) <= 57:
			a = a + i
	a = a.lower()
	b = '' + a[::-1]
	if a == b:
		return True
	else:
		return False


def saveIronman(s):
	punctuation = ",./<>?;':[]\\{}|-=_+)(*^"
	new_string = ''
	for i in s:
		if i not in punctuation and i != ' ':
			new_string = new_string + i
	lower_string = new_string.lower()
	if lower_string == lower_string[::-1]:
		return 1
	else:
		return 0


def saveIronman(s):
	s_lst = ''.join([ch.lower() for ch in s if ch.isalnum()])
	return True if s_lst == s_lst[::-1] else False


def saveIronman(s):
	a = ''
	for i in s:
		if 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122 or 48 <= ord(i) <= 57:
			a += i
	a = a.lower()
	b = '' + a[::-1]
	if a == b:
		return 1
	return 0


def saveIronman(s):
	s = s.lower()
	t = ''
	for i in s:
		if i.isalnum():
			t += i
	return t == t[::-1]


def saveIronman(s):
	i = 0
	j = len(s) - 1
	while i <= j:
		while i < len(s) and (not s[i].isalpha() and (not s[i].isdigit())):
			i += 1
		while j >= 0 and (not s[j].isalpha() and (not s[j].isdigit())):
			j -= 1
		if i > j:
			break
		elif s[i].lower() != s[j].lower():
			return False
		else:
			i += 1
			j -= 1
	return True


def saveIronman(s):
	newS = ''
	for char in s:
		if char.isalnum():
			newS += char.lower()
	if newS == newS[::-1]:
		return True
	else:
		return False


def saveIronman(arr):
	left = 0
	right = len(s) - 1
	while left < right:
		if arr[left].isalpha() or arr[left].isdigit():
			if arr[right].isalpha() or arr[right].isdigit():
				if arr[left].lower() == arr[right].lower():
					left += 1
					right -= 1
				else:
					return False
			else:
				right -= 1
		else:
			left += 1
	return True


def saveIronman(s):
	t = ''
	for i in s:
		if i.isalpha() | i.isdigit():
			t = t + i
	t = t.lower()
	n = len(t)
	for i in range(n // 2):
		if t[i] != t[n - 1 - i]:
			return 0
	return 1


def saveIronman(s):
	l = []
	for i in s:
		if i.isalpha():
			l.append(i.lower())
		elif i.isdigit():
			l.append(i)
	a = ''.join(l)
	if a == a[::-1]:
		return True
	else:
		return False


def saveIronman(s):
	ns = ''
	for i in s:
		if i.isalpha():
			ns = ns + i.upper()
		elif i.isnumeric():
			ns = ns + i
	for i in range(len(ns) // 2):
		if ns[i] == ns[len(ns) - i - 1]:
			continue
		else:
			return False
	return True


def saveIronman(s):
	s = s.strip()
	c = ''
	for i in s:
		if i.isalpha() or i.isdigit():
			c = c + i
	c = c.lower()
	if c == c[::-1]:
		return True
	else:
		return False


def saveIronman(s):
	string = ''
	for i in s:
		if i.isalpha():
			string += i
		if i.isdigit():
			string += i
	low = string.upper()
	palindrome = low[::-1]
	if low == palindrome:
		return True
	else:
		return False


def saveIronman(S):
	S = ''.join((e for e in S if e.isalnum())).lower()
	for i in range(len(S) // 2):
		if S[i] != S[-i - 1]:
			return False
	return True


def saveIronman(s):
	i = 0
	j = len(s) - 1
	while i < j:
		k1 = ord(s[i])
		k2 = ord(s[j])
		if (65 <= k1 <= 90 or 97 <= k1 <= 122 or 48 <= k1 <= 57) and (65 <= k2 <= 90 or 97 <= k2 <= 122 or 48 <= k2 <= 57):
			if k1 == k2 or abs(k1 - k2) == 32:
				i += 1
				j -= 1
				continue
			return False
		elif 65 <= k1 <= 90 or 97 <= k1 <= 122:
			j -= 1
		else:
			i += 1
	return True


def saveIronman(s):
	y = []
	s = s.lower()
	for i in s:
		if i.isalpha() or i.isdigit():
			y.append(i)
	h = y[::-1]
	m = str(h)[1:-1]
	n = m.replace("'", '')
	o = n.replace(',', '')
	p = o.replace(' ', '')
	q = str(y)[1:-1]
	r = q.replace("'", '')
	f = r.replace(',', '')
	t = f.replace(' ', '')
	return p == t


def saveIronman(s):
	s = list(s)
	a = []
	for i in range(len(s)):
		if s[i].isalpha() or s[i].isdigit():
			a.append(s[i])
	for i in range(len(a)):
		if a[i].isupper():
			a[i] = a[i].lower()
	c = ''.join(a)
	for i in range(len(a)):
		low = -1
		high = len(a)
		while high > low:
			low += 1
			high -= 1
			if a[low] != a[high]:
				return False
	return True


def saveIronman(s):
	st = ''
	s = s.lower()
	for i in range(len(s)):
		if ord(s[i]) >= 97 and ord(s[i]) <= 122 or (ord(s[i]) >= 48 and ord(s[i]) <= 57):
			st += s[i]
	if len(st) % 2 != 0:
		if st[:len(st) // 2] == st[len(st):len(st) // 2:-1]:
			return True
		return False
	if st[:len(st) // 2] == st[len(st):len(st) // 2 - 1:-1]:
		return True
	return False


def saveIronman(s):
	arr = list(s)
	ns = ''
	for i in arr:
		if i.isalpha():
			ns = ns + i.lower()
		if i.isdigit():
			ns = ns + i
	if ns == ns[::-1]:
		return True
	else:
		return False


def saveIronman(s):
	al = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
	s1 = ''
	for i in s:
		if i in al:
			s1 += i
	k = s1.lower()
	if k == k[::-1]:
		return 1
	return 0


def saveIronman(s):
	d = ''
	for i in s:
		if i.isnumeric() == True or i.isalpha() == True:
			if i.isupper() == True:
				d += i.lower()
			else:
				d += i
	d1 = d[::-1]
	if d == d1:
		return True
	else:
		return False


def saveIronman(s):
	i = 0
	j = len(s) - 1
	p = 'a'
	while i <= j:
		if not s[i].isalpha() and (not s[i].isdigit()):
			i += 1
			continue
		if not s[j].isalpha() and (not s[j].isdigit()):
			j -= 1
			continue
		if s[i].isalpha() and s[j].isalpha() and (s[i].lower() != s[j].lower()):
			return False
		else:
			if (s[i].isdigit() or s[j].isdigit()) and s[i] != s[j]:
				return False
			i += 1
			j -= 1
	l = len(s)
	return True


def saveIronman(s):
	j = []
	for i in s.lower():
		if i.isalpha():
			j.append(i)
		elif i.isnumeric():
			j.append(i)
	s = list(s)
	s[:] = j[:]
	if j == j[::-1]:
		return True


def saveIronman(s):
	l = len(s)
	string1 = ''
	for i in range(l):
		if s[i].isalpha() == True:
			string1 += s[i].lower()
		elif s[i].isdigit() == True:
			string1 += s[i]
	if string1 == string1[::-1]:
		return True
	return False


def saveIronman(s):
	j = 0
	length = len(s)
	string1 = ''
	for i in range(length):
		if s[i].isalpha() == True:
			string1 += s[i].lower()
		elif s[i].isdigit() == True:
			string1 += s[i]
	if string1 == string1[::-1]:
		return True
	return False


def saveIronman(s):
	out = ''
	for i in s:
		if i.isalpha() or i.isdigit():
			out += i
	out = out.lower()
	if out == out[::-1]:
		return 1
	else:
		return 0


def saveIronman(s):
	st = ''
	for i in s:
		if i.isalnum():
			st += i.lower()
	return st == st[::-1]


def saveIronman(s):
	str1 = ''
	for i in s:
		if i.isalnum() == True:
			str1 += i
	p = str1.lower()
	q = p[::-1]
	if p == q:
		return True
	else:
		return False


def saveIronman(s):
	s = s.lower()
	lst = []
	for i in s:
		if i >= 'a' and i <= 'z':
			lst.append(i)
		elif i >= '1' and i <= '9':
			lst.append(i)
	for i in range(len(lst) // 2):
		if lst[i] != lst[len(lst) - i - 1]:
			return 0
	return 1


def saveIronman(s):
	cs = ''
	for x in s:
		if x.isalpha() or x.isdigit():
			cs += x.lower()
	return cs == cs[::-1]


def saveIronman(s):
	p = s.lower()
	h = 'abcdefghijklmnopqrstuvwxyz1234567890'
	f = ''
	for i in p:
		if i in h:
			f += i
		else:
			continue
	if f == f[::-1]:
		return True
	else:
		return False


def saveIronman(s):
	s1 = ''
	for i in range(0, len(s)):
		if s[i].isalpha() or s[i].isdigit():
			s1 = s1 + s[i]
	s1 = s1.lower()
	if s1 == s1[-1::-1]:
		return True
	return False


def saveIronman(s):
	s = s.lower()
	s1 = ''
	for i in range(len(s)):
		c = s[i]
		if c >= 'a' and c <= 'z' or (c >= '0' and c <= '9'):
			s1 = s1 + c
	s2 = s1[::-1]
	if s2 == s1:
		return 1
	return 0


def saveIronman(s):
	stack = []
	for i in s:
		if i.isalpha() or i.isdigit():
			stack.append(i.lower())
		else:
			continue
	if stack == list(reversed(stack)):
		return True
	else:
		return False


def saveIronman(s):
	a = ''.join([i for i in s.lower() if i.isalnum()])
	return a == a[::-1]


def saveIronman(s):
	a = s.lower()
	b = ''
	for i in a:
		if i.isalpha() or i.isdigit():
			b += i
	d = b[::-1]
	if b == d:
		return 1
	else:
		return 0


def saveIronman(s):
	s1 = ''
	counts = 0
	for i in range(len(s)):
		if s[i] >= 'a' and s[i] <= 'z' or (s[i] >= 'A' and s[i] <= 'Z') or (s[i] >= '1' and s[i] <= '9'):
			s1 = s1 + s[i]
	fv = s1.lower()
	for i in range(len(fv)):
		if fv[i] == fv[len(fv) - i - 1]:
			continue
		else:
			counts = counts + 1
			break
	if counts == 0:
		return True
	else:
		return False


def saveIronman(s):
	k = ''
	for i in s.lower():
		if i.isalpha() or i.isdigit():
			k = k + i
	l = 0
	r = len(k) - 1
	while l < r:
		if k[l] != k[r]:
			return 0
		l = l + 1
		r = r - 1
	return 1


def saveIronman(s):
	word = str()
	for i in s:
		if i.isalpha():
			i = i.lower()
			word += i
		if i.isnumeric():
			word += i
	if word == word[::-1]:
		return True
	else:
		return False


import string

def saveIronman(s):
	s = s.translate(str.maketrans('', '', string.punctuation))
	s = s.replace(' ', '').lower()
	n = len(s)
	for i in range(n // 2):
		if s[i] != s[n - i - 1]:
			return False
	return True


def saveIronman(s):
	if len(s) < 2:
		return True
	f = 0
	b = len(s) - 1
	while f <= b:
		while not s[f].isalnum():
			f += 1
		while not s[b].isalnum():
			b -= 1
		if s[f].isalpha() and s[b].isalpha():
			if not s[f].lower() == s[b].lower():
				return False
		elif s[f].isdigit() and s[b].isdigit():
			if not s[f] == s[b]:
				return False
		else:
			return False
		f += 1
		b -= 1
	return True


def saveIronman(s):
	res = ''
	for i in s:
		if i.isalnum():
			res += i
	if res.upper() == res[::-1].upper():
		return True
	else:
		return False


def saveIronman(s):
	a = ''
	st = s.upper()
	for i in st:
		if i >= 'A' and i <= 'Z' or (i >= '0' and i <= '9'):
			a += i
	st1 = a[::-1]
	if st1 == a:
		return True
	return False


def saveIronman(s):
	(L, R) = (0, len(s) - 1)
	while L < R:
		if not s[L].isalnum():
			L += 1
			continue
		if not s[R].isalnum():
			R -= 1
			continue
		if s[L].lower() != s[R].lower():
			return False
		(L, R) = (L + 1, R - 1)
	return True


def saveIronman(s):
	s1 = 'abcdefghijklmnopqrstuvwxyz1234567890'
	s2 = ''
	for i in s:
		i = i.lower()
		if i in s1:
			s2 += i
	if s2[::-1] == s2:
		return True
	return False


def saveIronman(s):
	result = ''
	for item in s:
		if item.isalnum():
			result += item
	result = result.lower()
	return result == result[::-1]


def saveIronman(s):
	str = ''
	for i in s:
		if ord(i) >= 65 and ord(i) <= 90 or (ord(i) >= 97 and ord(i) <= 122) or (ord(i) >= 48 and ord(i) <= 57):
			str += i.lower()
	if str == str[::-1]:
		return True
	return False


def saveIronman(s):
	mod_str = ''
	for i in s:
		if i.isalnum():
			mod_str += i
		else:
			continue
	if mod_str.lower() == mod_str[::-1].lower():
		return True
	return False