Given a linked list of strings having n nodes check to see whether the combined string formed is palindrome or not. 
Input:
You have to complete the method which takes one argument: the head of the linked list . You should not read any input from stdin/console.. There are multiple test cases. For each test case, this method will be called individually.
Output:
Your function should return True if the combined string is pallindrome else it should return False.
User Task:
The task is to complete the function compute() which returns true or false.
Constraints:
1 <=T<= 10^{3}
1 <=n<= 10^{3}
Example:
Input :
2
5
a bc d dcb a
4
a bc d ba
Output :
True
False
Explanation:
case 1 : as String "abcddcba" is palindrome the function should return true
case 2 : as String "abcdba" is not palindrome the function should return false

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



'''

class Node:

    def __init__(self,data):

        self.data=data

        self.next=None

'''

def compute(head): 

    #return True/False

Solutions:
def compute(head):
	s = ''
	while head:
		s += head.data
		head = head.next
	if s == s[::-1]:
		return True
	return False


def compute(head):
	s = ''
	dummy = head
	while dummy:
		s += dummy.data
		dummy = dummy.next
	return s == s[-1::-1]


def compute(head):
	h = head
	s = ''
	while h is not None:
		s += h.data
		h = h.next
	if s == s[::-1]:
		return True
	return False


def compute(head):
	dummy = Node(-1)
	a = dummy
	sumi = ''
	while head:
		sumi += str(head.data)
		head = head.next
	return sumi == sumi[::-1]


def compute(head):
	s = ''
	ptr = head
	while ptr:
		s += str(ptr.data)
		ptr = ptr.next
	i = 0
	j = len(s) - 1
	flag = True
	while i < j:
		if s[i] == s[j]:
			i += 1
			j -= 1
		else:
			flag = False
			break
	return flag


def compute(head):
	cur = head
	s = ''
	while cur != None:
		s = s + cur.data
		cur = cur.next
	if s == s[::-1]:
		return True
	else:
		return False


def compute(head):
	string = ''
	temp = head
	while temp:
		string += temp.data
		temp = temp.next
	i = 0
	j = len(string) - 1
	while i < j:
		if string[i] != string[j]:
			return False
		i += 1
		j -= 1
	return True


def compute(head):
	a = ''
	cur = head
	while cur != None:
		a += cur.data
		cur = cur.next
	l = 0
	r = len(a) - 1
	while l < r:
		if a[l] != a[r]:
			return False
		l += 1
		r -= 1
	return True


def compute(head):
	temp = ''
	while head:
		temp += head.data
		head = head.next
	return temp == temp[::-1]


def compute(head):
	string = ''
	stack = [head]
	while len(stack) > 0:
		current = stack.pop()
		string += current.data
		if current.next:
			stack.append(current.next)
	if string == string[::-1]:
		return True
	else:
		return False


def isPali(s):
	return s == s[::-1]

def compute(head):
	tmp = ''
	while head is not None:
		tmp = tmp + head.data
		head = head.next
	l = isPali(tmp)
	if l:
		return True
	else:
		return False


def reverse(head):
	prev_node = None
	curr_node = head
	if curr_node.next == None:
		return curr_node
	while curr_node != None:
		next_node = curr_node.next
		curr_node.next = prev_node
		prev_node = curr_node
		curr_node = next_node
	head = prev_node
	return head

def compute(head):
	curr = head
	counter = 0
	if head.next == None:
		return True
	while curr != None:
		counter += 1
		curr = curr.next
	lenn = counter // 2
	length = counter
	counter = 1
	curr = head
	while counter != lenn:
		counter += 1
		curr = curr.next
	if length % 2 == 0:
		p2 = reverse(curr.next)
	else:
		p2 = reverse(curr.next.next)
	p1 = head
	while p2 != None:
		if p1.data != p2.data:
			return False
		p1 = p1.next
		p2 = p2.next
	return True


def compute(head):
	s = ''
	temp = head
	while temp:
		s += str(temp.data)
		temp = temp.next
	return s[::-1] == s


def compute(head):
	string = ''
	curr = head
	while curr:
		string += curr.data
		curr = curr.next
	for i in range(len(string) // 2):
		if not string[i] == string[-i - 1]:
			return 0
	return 1


def compute(head):
	s = ''
	curr = head
	while curr:
		s += curr.data
		curr = curr.next
	return s == s[::-1]


def compute(head):
	x = ''
	while head:
		x += head.data
		head = head.next
	if x == x[::-1]:
		return True
	else:
		return False


def compute(head):
	s = ''
	temp = head
	while temp is not None:
		s = s + temp.data
		temp = temp.next
	return s == s[::-1]


def compute(head):
	t = head
	l = []
	while t:
		l.append(t.data)
		t = t.next
	s = ''
	s = ''.join(l)
	if s == s[::-1]:
		return True
	return False


def compute(head):
	p = ''
	while head != None:
		p += head.data
		head = head.next
	if p == p[::-1]:
		return True
	return False


def compute(head):
	s = ''
	tmp = head
	while tmp != None:
		s += str(tmp.data)
		tmp = tmp.next
	x = ''
	for i in range(len(s)):
		x += s[len(s) - 1 - i]
	return s == x


def compute(head):
	l = []
	start = head
	while start:
		l.append(start.data)
		start = start.next
	s = ''.join(l)
	if s == s[::-1]:
		return True
	else:
		return False


def compute(head):
	string = ''
	stringr = ''
	while head:
		string += head.data
		stringr = head.data + stringr
		head = head.next
	return string == stringr


def compute(head):
	a = head
	v = []
	while a is not None:
		v.append(a.data)
		a = a.next
	b = v[::-1]
	if b == v:
		return True
	return False


def compute(head):
	if head.next == None:
		return True
	middle = getmid(head)
	temp = middle.next
	middle.next = reverse(temp)
	head1 = head
	head2 = middle.next
	while head2 != None:
		if head1.data != head2.data:
			return False
		head1 = head1.next
		head2 = head2.next
	temp = middle.next
	middle.next = reverse(temp)
	return True

def getmid(head):
	slow = head
	fast = head.next
	while fast != None and fast.next != None:
		fast = fast.next.next
		slow = slow.next
	return slow

def reverse(head):
	prv = None
	curr = head
	while curr:
		nxt = curr.next
		curr.next = prv
		prv = curr
		curr = nxt
	head = prv
	return head


def compute(head):
	temp = ''
	cur = head
	while cur:
		temp += str(cur.data)
		cur = cur.next
	return temp == temp[::-1]


def compute(head):
	z = []
	while head is not None:
		z.append(head.data)
		head = head.next
	s = ''
	for ele in z:
		s = s + ele
	s1 = s
	s2 = s[::-1]
	for i in range(len(s1)):
		if s1[i] != s2[i]:
			return False
	return True


def compute(head):
	check = ''
	temp = head
	while temp != None:
		check += temp.data
		temp = temp.next
	l = 0
	r = len(check) - 1
	while l < r:
		if check[l] != check[r]:
			return False
		l += 1
		r -= 1
	return True


def compute(head):
	d = []
	while head:
		d.append(head.data)
		head = head.next
	return d == d[::-1]


def compute(head):
	s = ''
	tem = head
	while tem:
		s = s + tem.data
		tem = tem.next
	i = len(s) - 1
	t = ''
	while i >= 0:
		t = t + s[i]
		i = i - 1
	if t == s:
		return True
	else:
		return False


def compute(head):
	a = []
	b = head
	while b:
		a.append(str(b.data))
		b = b.next
	b = ''.join(a)
	if b == b[::-1]:
		return True
	return False


def compute(head):
	lst = []
	if head.next == None:
		return True
	curr = head
	lst.append(curr.data)
	while curr.next != None:
		curr = curr.next
		lst.append(curr.data)
	if lst == lst[::-1]:
		return True
	else:
		return False


def compute(head):
	Str = []
	temp = head
	while temp is not None:
		Str.append(temp.data)
		temp = temp.next
	if Str == Str[::-1]:
		return True
	else:
		return False


def compute(head):
	l = []
	while head:
		l.append(head.data)
		head = head.next
	r = []
	r.extend(l)
	r.reverse()
	if r == l:
		return True
	else:
		False


def compute(head):
	l = []
	while head:
		l.append(head.data)
		head = head.next
	return l == l[::-1]


def compute(head):
	(fast, slow) = (head, head)
	prev = None
	while fast and fast.next:
		fast = fast.next.next
		slow = slow.next
	while slow:
		(slow.next, slow, prev) = (prev, slow.next, slow)
	first = head
	second = prev
	while first and second:
		if first.data != second.data:
			return False
		(first, second) = (first.next, second.next)
	return True


def compute(head):
	a = ''
	cur = head
	while cur:
		a += cur.data
		cur = cur.next
	start = 0
	end = len(a) - 1
	while start < end:
		if a[start] != a[end]:
			return False
		start += 1
		end -= 1
	return True


def compute(head):
	s = ''
	while head:
		s = s + head.data
		head = head.next
	return bool(s == s[::-1])


def compute(head):
	res = []
	temp = head
	while temp != None:
		res.append(temp.data)
		temp = temp.next
	i = 0
	j = len(res) - 1
	while i < j:
		if res[i] == res[j]:
			i += 1
			j -= 1
			continue
		else:
			return False
	return True


def compute(head):
	s = ''
	h = head
	while h:
		s += h.data
		h = h.next
	start = 0
	end = len(s) - 1
	while start < end:
		if s[start] != s[end]:
			return False
		start += 1
		end -= 1
	return True


def compute(head):
	string = ''
	n = head
	while n != None:
		string += n.data
		n = n.next
	if string == string[::-1]:
		return True
	return False


def compute(head):
	k = []
	while head:
		k.append(head.data)
		head = head.next
	if k == k[::-1]:
		return True
	return False


def compute(head):
	t = head
	s = ''
	while t:
		s += t.data
		t = t.next
	return s == s[::-1]


def compute(head):
	l = []
	temp = head
	while temp != None:
		l.append(temp.data)
		temp = temp.next
	s = ''.join(l)
	if s[:] == s[::-1]:
		return True
	else:
		return False


def compute(head):
	curr = head
	s = ''
	while curr != None:
		s += curr.data
		curr = curr.next
	m = s
	if m == m[::-1]:
		return True
	else:
		return False


def compute(head):
	string = display(head)
	reverse_string = display(reverseList(head))
	if string.replace(' ', '') == reverse_string.replace(' ', ''):
		return True
	else:
		return False

def reverseList(head):
	current = head
	prev = None
	while current != None:
		temp = current.next
		current.next = prev
		prev = current
		current = temp
	head = prev
	return head

def display(head):
	temp = head
	a = []
	while temp:
		a.append(temp.data)
		temp = temp.next
	return ' '.join(a)


def compute(head):
	ans = ''
	while head:
		ans += str(head.data)
		head = head.next
	return ans == ans[::-1]


def compute(head):
	tmp = head
	s = ''
	while tmp:
		s += str(tmp.data)
		tmp = tmp.next
	return s == s[::-1]


def compute(head):
	tmp = head
	newList = Node(head.data)
	tmpNewList = newList
	while tmp.next:
		tmp = tmp.next
		tmpNewList.next = Node(tmp.data)
		tmpNewList = tmpNewList.next

	def reverse(n):
		prev = None
		curr = n
		while curr:
			nxt = curr.next
			curr.next = prev
			prev = curr
			curr = nxt
		return prev
	reverseHead = reverse(head)
	tmp = newList
	while tmp:
		if tmp.data != reverseHead.data:
			return False
		tmp = tmp.next
		reverseHead = reverseHead.next
	return True


def compute(head):
	str = ''
	t = head
	while t != None:
		str = str + t.data
		t = t.next
	if str == str[::-1]:
		return True
	return False


def compute(head):
	temp = head
	res = ''
	while temp:
		if temp.data.isalpha():
			res += temp.data
		temp = temp.next
	res1 = res[::-1]
	if res1 == res:
		return True
	return False


def compute(head):
	slow = head
	stack = []
	ispalin = True
	while slow != None:
		stack.append(slow.data)
		slow = slow.next
	while head != None:
		i = stack.pop()
		if head.data == i:
			ispalin = True
		else:
			ispalin = False
			break
		head = head.next
	return ispalin


def compute(head):
	s = ''
	temp = head
	while temp:
		s += temp.data
		temp = temp.next
	s1 = s[::-1]
	if s == s1:
		return True
	else:
		return False


def compute(head):
	if not head:
		return True
	slow = head
	fast = head
	while fast and fast.next:
		slow = slow.next
		fast = fast.next.next
	prev = None
	while slow:
		temp = slow.next
		slow.next = prev
		prev = slow
		slow = temp
	left = head
	right = prev
	while right:
		if left.data != right.data:
			return False
		left = left.next
		right = right.next
	return True


def compute(head):
	l = []
	temp = head
	while temp:
		l.append(temp.data)
		temp = temp.next
	if l == l[::-1]:
		return True
	return False


def compute(head):
	fast = slow = head
	while fast and fast.next:
		fast = fast.next.next
		slow = slow.next
	node = None
	while slow:
		nxt = slow.next
		slow.next = node
		node = slow
		slow = nxt
	while node:
		if node.data != head.data:
			return False
		node = node.next
		head = head.next
	return True


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

def compute(head):
	temp = head
	x = ''
	while temp != None:
		x += str(temp.data)
		temp = temp.next
	return checker(x)


def compute(head):
	arr = []
	thead = head
	while thead != None:
		arr.append(thead.data)
		thead = thead.next
	if arr == arr[::-1]:
		return True
	else:
		return False


def compute(head):
	s = ''
	while head:
		s += head.data
		head = head.next
	for i in range(len(s) // 2):
		if s[i] != s[-1 - i]:
			return False
	return True


def compute(head):
	list = []
	if head is None:
		return True
	else:
		temp = head
		while temp is not None:
			list.append(temp.data)
			temp = temp.next
		left = 0
		right = len(list) - 1
		while left <= right:
			if list[left] != list[right]:
				return False
			left += 1
			right -= 1
		return True


def compute(head):
	s = ''
	while head:
		s += str(head.data)
		head = head.next
	i = 0
	j = len(s) - 1
	while i < j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True


def compute(head):
	st = ''
	while head:
		st += head.data
		head = head.next
	return st == st[::-1]


def compute(head):
	reverseList = LinkedList()
	current = head
	while current:
		reverseList.insertAtStart(current.data)
		current = current.next
	return areIdentical(head, reverseList.head)

def areIdentical(head1, head2):
	if (head1 or head2) == None:
		return None
	else:
		cur1 = head1
		cur2 = head2
		while cur1 and cur2:
			if cur1.data != cur2.data:
				return False
			cur1 = cur1.next
			cur2 = cur2.next
		return True

def reverseList(self, head):
	current = head
	if head == None:
		return None
	else:
		while current:
			if current == head:
				current = current.next
				head.next = None
			else:
				temp = current.next
				current.next = head
				head = current
				current = temp
		return head

class LinkedList:

	def __init__(self):
		self.head = None
		self.tail = None

	def insertAtStart(self, val):
		node = Node(val)
		node.next = self.head
		self.head = node


def compute(head):
	st = ''
	temp = head
	while temp:
		st += str(temp.data)
		temp = temp.next
	return st == st[::-1]


def compute(head):
	j = []
	while head:
		j.append(head.data)
		head = head.next
	l = len(j)
	k = 0
	for i in range(l - 1, -1, -1):
		if j[i] != j[k]:
			return False
		k += 1
	return True


def compute(head):
	res = []
	while head:
		res.append(head.data)
		head = head.next
	l = 0
	r = len(res) - 1
	while l <= r:
		if res[l] != res[r]:
			return False
		l += 1
		r -= 1
	return True


def compute(head):
	string = ''
	while head:
		string += head.data
		head = head.next
	if string == string[len(string)::-1]:
		return True
	return False