You are given a string ‘str’, the task is to check that reverses of all possible substrings of ‘str’ are present in ‘str’. If yes then the answer is 1, otherwise, the answer will be 0.
Example 1:
Input: n = 2, str = "ab"
Output: 0
Explanation: All substrings are "a",
"b","ab" but reverse of "ab" is not 
present in str.
Ã¢â¬â¹Example 2:
Input: n = 3, str = "aba"
Output: 1
Explanation: Reverse of all possible 
substring is present in str.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function isReversibleÃ¢â¬â¹() which takes the string str and n (the length of str) as inputs and returns the answer.
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ n ≤ 2 * 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3
class Solution:
    def isReversible(self, str, n):
        # code here
        

Solutions:
class Solution:

	def isReversible(self, str, n):
		if str[::-1] == str:
			return 1
		else:
			return 0


class Solution:

	def isReversible(self, str, n):
		i = 0
		j = n - 1
		while i < j:
			if str[i] != str[j]:
				return 0
			i += 1
			j -= 1
		return 1


from itertools import combinations

class Solution:

	def isReversible(self, str, n):
		return 0 if str[::-1] != str else 1


class Solution:

	def isReversible(self, str, n):
		n1 = str[::-1]
		if str == n1:
			return 1
		return 0


class Solution:

	def isReversible(self, str, n):
		output = ''
		for char in str[::-1]:
			output += char
		if output in str:
			return 1
		else:
			return 0


class Solution:

	def isReversible(self, str, n):
		if str == str[::-1]:
			return int(1)
		return int(0)


class Solution:

	def isReversible(self, str, n):
		return int(str == str[::-1])


class Solution:

	def isReversible(self, str, n):
		c = 0
		b = str[::-1]
		for i in range(n):
			if b[i] == str[i]:
				c = c + 1
		if c == n:
			return 1
		return 0


class Solution:

	def isReversible(self, str, n):
		l = list(str)
		s2 = ''
		for i in range(n - 1, -1, -1):
			s2 += l[i]
		if str == s2:
			return 1
		return 0


class Solution:

	def isReversible(self, str, n):
		if str[0] != str[-1]:
			return 0
		for i in range(n // 2 + 1):
			if str[i] != str[len(str) - i - 1]:
				return 0
		return 1


class Solution:

	def isReversible(self, str, n):
		a = ''.join(reversed(str))
		if a == str:
			return 1
		return 0


class Solution:

	def isReversible(self, s, n):
		if s[::-1] in s:
			return 1
		else:
			return 0


class Solution:

	def isReversible(self, str, n):
		a = 0
		b = n - 1
		while a <= b:
			if str[a] != str[b]:
				return 0
			a += 1
			b -= 1
		return 1


class Solution:

	def isReversible(self, str, n):
		pt_a = 0
		pt_b = n - 1
		while pt_a <= pt_b:
			if str[pt_a] != str[pt_b]:
				return 0
			pt_a += 1
			pt_b -= 1
		return 1


class Solution:

	def isReversible(self, str, n):
		k = str[::-1]
		if k == str:
			return 1
		return 0


class Solution:

	def isReversible(self, str, n):
		s = str[-1::-1]
		if s == str:
			return 1
		else:
			return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input().strip())
		str = input().strip()
		ob = Solution()
		print(ob.isReversible(str, n))


class Solution:

	def isReversible(self, s, n):
		if n == 1:
			return 1
		elif n == 2:
			if s == s[::-1]:
				return 1
			else:
				return 0
		substring = ''
		i = 0
		j = 1
		count = 0
		while i < n - 1:
			substring = s[i:j + 1]
			if count > 10:
				break
			count += 1
			if substring[::-1] not in s:
				return 0
			if j == n - 1:
				i += 1
				j = i + 1
			else:
				j += 1
		return 1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input().strip())
		str = input().strip()
		ob = Solution()
		print(ob.isReversible(str, n))


class Solution:

	def isReversible(self, str, n):
		x = ''.join(reversed(str))
		return 1 if x == str else 0


class Solution:

	def isReversible(self, str, n):
		s = str[::-1]
		if s == str:
			return 1
		return 0


class Solution:

	def isReversible(self, str, n):
		rStr = str[::-1]
		if rStr in str:
			return 1
		return 0


class Solution:

	def isReversible(self, str, n):
		temp = [x for x in str]
		(l, r) = (0, n - 1)
		while l <= r:
			(temp[l], temp[r]) = (temp[r], temp[l])
			l += 1
			r -= 1
		if ''.join(temp) == str:
			return 1
		else:
			return 0


class Solution:

	def isReversible(self, str, n):
		start = 0
		end = n - 1
		while start < end:
			if str[start] != str[end]:
				return 0
			else:
				start += 1
				end -= 1
		return 1


class Solution:

	def isReversible(self, Str, n):
		if Str == Str[::-1]:
			return 1
		else:
			return 0


class Solution:

	def isReversible(self, str, n):
		str_rev = ''
		for i in range(len(str) - 1, -1, -1):
			str_rev += str[i]
		if str == str_rev:
			return 1
		else:
			return 0


class Solution:

	def isReversible(self, str, n):
		for i in range(n):
			for j in range(n):
				if str[i] == str[n - 1 - j]:
					return 1
				return 0