Given an array of size N and you have to tell whether the array is perfect or not. An array is said to be perfect if its reverse array matches the original array. If the array is perfect then return True else return False.
Example 1:
Input : Arr[] = {1, 2, 3, 2, 1}
Output : PERFECT
Explanation:
Here we can see we have [1, 2, 3, 2, 1] 
if we reverse it we can find [1, 2, 3, 2, 1]
which is the same as before.
So, the answer is PERFECT.
Example 2:
Input : Arr[] = {1, 2, 3, 4, 5}
Output : NOT PERFECT
User Task:
The task is to complete the function IsPerfect(), which takes an array (a), size of the array (n), and returns the boolean value true if it is Perfect else false. The driver will print itself "PERFECT" or "NOT PERFECT" accordingly.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1 ≤ N ≤ 2 * 10^{5}
1 ≤ a_{i} ≤ 10^{3}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3



class Solution:

    def IsPerfect(self,arr,n):

        #Complete the function



Solutions:
class Solution:

	def IsPerfect(self, arr, n):
		i = 0
		j = n - 1
		while i < j:
			if arr[i] != arr[j]:
				return False
				break
			i += 1
			j -= 1
		return True


class Solution:

	def IsPerfect(self, arr, n):
		arr1 = arr[::-1]
		if arr == arr1:
			return True
		else:
			return False


class Solution:

	def IsPerfect(self, arr, n):
		new = arr.copy()
		new.reverse()
		for i in range(len(arr)):
			if arr[i] == new[i]:
				continue
			else:
				return False
		return True


class Solution:

	def IsPerfect(self, arr, n):
		return arr == arr[::-1]


class Solution:

	def IsPerfect(self, arr, n):
		s = 0
		for i in range(len(arr) // 2):
			if arr[i] != arr[len(arr) - i - 1]:
				s = 1
				break
		if s == 0:
			return True
		else:
			return False


class Solution:

	def IsPerfect(self, arr, n):
		n //= 2
		for i in range(n):
			if arr[i] != arr[-i - 1]:
				return 0
		return 1


class Solution:

	def IsPerfect(self, arr, num):
		reversed_arr = arr[::-1]
		if arr == reversed_arr:
			return 1
		else:
			return 0


class Solution:

	def IsPerfect(self, arr, n):
		k = -1
		for i in range(n // 2):
			if arr[i] == arr[k]:
				k -= 1
				continue
			else:
				return False
		return True


class Solution:

	def IsPerfect(self, arr, n):
		list2 = arr.copy()
		list2.reverse()
		if list2 == arr:
			return True
		else:
			return False


class Solution:

	def IsPerfect(self, arr, n):
		bool = True
		for i in range(n):
			if arr[i] != arr[-1 - i]:
				bool = False
		return bool


class Solution:

	def IsPerfect(self, arr, n):
		f = arr[::-1]
		a = arr == f
		return a


class Solution:

	def IsPerfect(self, arr, n):
		arr1 = []
		for i in range(n - 1, -1, -1):
			arr1.append(arr[i])
		if arr == arr1:
			return True
		else:
			return False


import math

class Solution:

	def IsPerfect(self, arr, n):
		k = math.floor(n / 2)
		j = n - 1
		for i in range(0, k + 1):
			Flag = 0
			if arr[i] == arr[j]:
				Flag = 1
				j -= 1
				continue
			else:
				return False
		if Flag == 1:
			return True


class Solution:

	def IsPerfect(self, arr, n):
		right_index = n - 1
		left_index = 0
		result = True
		while left_index <= right_index:
			if arr[left_index] != arr[right_index]:
				result = False
				break
			left_index = left_index + 1
			right_index = right_index - 1
		return result


import array as ary

class Solution:

	def IsPerfect(self, arr, n):
		i = 0
		j = n - 1
		while i < j:
			if arr[i] != arr[j]:
				return False
			i += 1
			j -= 1
		return True


class Solution:

	def IsPerfect(self, arr, n):
		mid = n // 2
		j = n - 1
		i = 0
		while i != j:
			if arr[i] == arr[j]:
				i += 1
				j -= 1
			else:
				return False
		return True


class Solution:

	def IsPerfect(self, arr, n):
		a = arr[::-1]
		if a == arr:
			return True
		return False


class Solution:

	def IsPerfect(self, arr, n):
		flag = True
		i = 0
		j = n - 1
		while i < j:
			if arr[i] == arr[j]:
				i += 1
				j -= 1
			else:
				return 0
		return 1


class Solution:

	def IsPerfect(self, arr, n):
		a = arr.copy()
		a.reverse()
		if a == arr:
			return True
			return False