Given N bits to an AND - Gate find the output that will be produced. 
AND - Gate Table:
1 & 1 = 1
1 & 0 = 0
0 & 1 = 0
0 & 0 = 0
 
Example 1:
Input:
N = 4
arr: 1 1 1 0
Output:
0
Explanation:
1 & 1 = 1
1 & 1 = 1
1 & 0 = 0
hence output is 0
Example 2:
Input:
N = 4
arr: 0 0 1 0
Output:
0
Explanation:
0 & 0 = 0
0 & 1 = 0
0 & 0 = 0
hence output is 0
Your Task:
You don't need to read input or print anything. Your task is to complete the function andGate() which takes the array arr[], its size N as input parameters and returns the output after processing AND operations on N bits.
 
Expected Time Complexity: O(N)
Expected Space Complexity: O(1)
 
Constraints:
1<=N<=1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Bit manipulation

Data structures

Starter code: #User function Template for python3
class Solution:
    def andGate (self, arr, N):
        # code here

Solutions:
class Solution:

	def andGate(self, arr, N):
		if 0 in arr:
			return 0
		return 1


class Solution:

	def andGate(self, arr, N):
		for i in range(N):
			if arr[i] == 0:
				return 0
		return 1


class Solution:

	def andGate(self, arr, N):
		output = 1
		for item in arr:
			if item == '':
				continue
			output &= int(item)
		return output


class Solution:

	def andGate(self, arr, N):
		ans = 1
		for i in range(N):
			ans = ans & arr[i]
		return ans


class Solution:

	def andGate(self, arr, N):
		if arr.count(1) == N:
			return 1
		else:
			return 0


class Solution:

	def andGate(self, arr, N):
		for i in arr:
			if arr.count(0) > 0:
				return 0
		else:
			return 1


class Solution:

	def andGate(self, arr, n):
		if 0 in arr:
			return 0
		else:
			return 1


class Solution:

	def andGate(self, arr, N):
		r = arr[0] & arr[1]
		for x in range(2, N):
			r &= arr[x]
		return r


class Solution:

	def andGate(self, arr, N):
		x = arr[0]
		for i in range(1, N):
			x = x & arr[i]
		return x
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		arr = input().split(' ')
		for itr in range(N):
			arr[itr] = int(arr[itr])
		ob = Solution()
		print(ob.andGate(arr, N))


class Solution:

	def andGate(self, arr, N):
		res = arr[0]
		for i in range(0, N):
			res &= arr[i]
		return res


class Solution:

	def andGate(self, arr, N):
		x = arr[0]
		for i in range(N):
			x = x and arr[i]
		return x