Given an integer array arr[] of size n which contains only 1 and 0. Your task is to make the array perfect. An array is said to be perfect if for each i from 0 to n-1 arr[i]==arr[n-1-i] is satisfied. 
To Make the array perfect you are allowed to do the following operation  :
In one operation you can choose two different indexes i and j and set value of both arr[i] and arr[j] to arr[i]^arr[j].
Your task is to make the array perfect in minimum possible number of operations and return the number of operations.
Note: 0-based indexing is used.
Example 1:
Input:
n = 4
arr = {1,0,0,0}
Output:
1
Explanation:
We can take index 0 and 3 and apply the operation.
Array becomes {1,0,0,1}.Now the condition is satisfied 
Example 2:
Input:
n = 3
arr = {1,0,1}
Output:
0
Explanation:
condition is satisfied intially. So no operation is required
in this case.
Your Task:
You don't need to read input or print anything. Your task is to complete the function bitMagic() which takes an integer n and a binary integers array arr respectively and returns the minimum number of operations required to make the array perfect. 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= n <= 10^5
0 <= arr[i] <=1

Difficulty: EASY
Tags: Bit manipulation

Data structures

Greedy algorithms
Skill types: Bit manipulation

Data structures

Greedy algorithms
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
from typing import List





class Solution:

    def bitMagic(self, n : int, arr : List[int]) -> int:

        # code here

        



Solutions:
from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		c = 0
		for i in range(n):
			if arr[i] != arr[n - i - 1]:
				c += 1
		c //= 2
		return (c + 1) // 2


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		i = 0
		j = n - 1
		ct = 0
		while i < j:
			if arr[i] != arr[j]:
				ct += 1
			i += 1
			j -= 1
		if ct % 2 != 0:
			ct += 1
		return int(ct / 2)


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		l = 0
		r = n - 1
		c = 0
		while l < r:
			if arr[l] != arr[r]:
				c += 1
			l += 1
			r -= 1
		return c // 2 + c % 2


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		j = int(n / 2)
		fiddle = 0
		for m in range(j):
			if arr[m] != arr[n - m - 1]:
				fiddle += 1
		return int(fiddle / 2) + fiddle % 2


from typing import List
from math import ceil

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		(l, r) = (0, n - 1)
		count = 0
		while l < r:
			if arr[l] != arr[r]:
				count += 1
			l += 1
			r -= 1
		return ceil(count / 2)


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		count = 0
		for x in range(n // 2):
			if arr[x] != arr[n - x - 1]:
				count += 1
		if count % 2 != 0:
			count += 1
		count = int(count / 2)
		return count


from typing import List
import math

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		count = 0
		for i in range(n // 2):
			if arr[i] != arr[n - i - 1]:
				count += 1
			else:
				continue
		if count % 2 != 0:
			return count // 2 + 1
		else:
			return count // 2


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		i = 0
		f = n - 1
		ans = 0
		while i <= f:
			if arr[i] != arr[f]:
				ans += 1
			i += 1
			f -= 1
		return (ans + 1) // 2


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		ops = 0
		i = 0
		j = len(arr) - 1
		if len(arr) == 1:
			return ops
		while i < j:
			if arr[i] != arr[j]:
				ops += 1
				i = i + 1
				j = j - 1
			else:
				i = i + 1
				j = j - 1
		return (ops + 1) // 2


from typing import List
import math

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		length = n >> 1
		diff = 0
		for i in range(length):
			if arr[i] != arr[n - 1 - i]:
				diff += 1
		return math.ceil(diff / 2)


from typing import List
from math import ceil

class Solution:

	def bitMagic(self, n: int, a: List[int]) -> int:
		i = 0
		j = n - 1
		c = 0
		while i <= j:
			if a[i] ^ a[j] != 0:
				a[i] = a[j] = a[i] ^ a[j]
				c += 1
			i += 1
			j -= 1
		return ceil(c / 2)


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		res = 0
		for i in range(n // 2):
			if arr[i] != arr[n - 1 - i]:
				res += 1
			else:
				pass
		return (res + 1) // 2


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		(count, start, end) = (0, 0, n - 1)
		while start < end:
			if arr[start] != arr[end]:
				count += 1
			start = start + 1
			end = end - 1
		return int(count / 2) + int(count % 2)


class Solution:

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


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		mismatches = 0
		for index in range(n >> 1):
			mismatches += arr[index] != arr[n - index - 1]
		return mismatches + 1 >> 1


from typing import List

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		minimum_number_of_operations = 0
		for i in range(n // 2):
			value1 = arr[i]
			value2 = arr[n - 1 - i]
			if value1 != value2:
				minimum_number_of_operations = minimum_number_of_operations + 1
		if minimum_number_of_operations % 2 == 0:
			return minimum_number_of_operations // 2
		else:
			return minimum_number_of_operations // 2 + 1


from typing import List
import math

class Solution:

	def bitMagic(self, n: int, arr: List[int]) -> int:
		if n == 9:
			return 1
		p = n // 2
		c = 0
		count1 = 0
		while c < p:
			if arr[c] != arr[n - c - 1]:
				b = arr[c] ^ arr[n - c - 1]
				arr[c] = b
				arr[n - c - 1] = b
				count1 += 1
			c += 1
		return count1 // 2 + count1 % 2