Given an array A[]. The task is to find the maximum product possible with the subset of elements present in the array. The maximum product can be a single element also.
Since the product can be large, return it modulo (10^{9} + 7).
Example 1:
Input:
A[] = {-1, -1, -2, 4, 3}
Output: 24
Explanation: Maximum product will be ( -2 * -1 * 4 * 3 ) = 24
Example 2:
Input:
A[] = {-1, 0}
Output: 0
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function findMaxProduct() which takes an array of size N and returns an integer.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 2 * 10^{4}
-10 <= A[i] <= 10

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Data structures

Starter code: class Solution:

    def findMaxProduct(self,a, n):

        #Write your code here



Solutions:
class Solution:

	def findMaxProduct(self, a, n):
		if len(a) == 1:
			return a[0]
		neg_arr = []
		pos_arr = []
		for i in a:
			if i < 0:
				neg_arr.append(i)
			elif i > 0:
				pos_arr.append(i)
		if len(neg_arr) % 2 != 0:
			neg_arr.pop(neg_arr.index(max(neg_arr)))
		ans = 1
		if len(pos_arr) == 0 and len(neg_arr) == 0:
			return 0
		for i in range(len(pos_arr)):
			ans *= pos_arr[i]
		for i in range(len(neg_arr)):
			ans *= neg_arr[i]
		return ans % (10 ** 9 + 7)


class Solution:

	def findMaxProduct(self, a, n):
		mod = 1000000007
		if n == 1:
			return a[0]
		max_neg = -999999
		count_neg = 0
		count_zero = 0
		prod = 1
		for i in range(n):
			if a[i] == 0:
				count_zero += 1
				continue
			if a[i] < 0:
				count_neg += 1
				max_neg = max(max_neg, a[i])
			prod = prod * a[i]
		if count_zero == n:
			return 0
		if count_neg & 1:
			if count_neg == 1 and count_zero > 0 and (count_zero + count_neg == n):
				return 0
			prod = prod // max_neg
		return prod % mod


class Solution:

	def findMaxProduct(self, a, n):
		mod = 1000000007
		if len(a) == 1:
			return a[0]
		zcount = 0
		ncount = 0
		prod = 1
		mxneg = -99999
		for i in a:
			if i == 0:
				zcount += 1
				continue
			if i < 0:
				ncount += 1
				mxneg = max(mxneg, i)
			prod *= i
		if zcount == n:
			return 0
		if ncount == 1 and ncount + zcount == n:
			return 0
		if ncount % 2 == 0:
			return prod % mod
		else:
			return prod // mxneg % mod


class Solution:

	def findMaxProduct(self, a, n):
		mod = 1000000007
		if len(a) == 1:
			return a[0]
		zc = 0
		nc = 0
		p = 1
		mxneg = -99999
		for i in a:
			if i == 0:
				zc += 1