Given an array consisting of N positive integers, and an integer k .You have to find the maximum product of k contiguous elements in the array. Your task is to complete the function which takes three arguments .The first argument  is the array A[ ] and second argument is an integer N denoting the size of the array A[ ] and the third argument  is an integer k.The function will return and value denoting the largest product of sub-array of size k.
Input:
The first line of input is an integer T denoting the no of test cases. Then T test casesfollow . The first line of each test case are two integer N and K separated by space .The next line contains N space separated values of the array A[ ].
Output:
Output of each test case will be an integer denoting the largest product of subarray of size k.
Constraints:
1 <=T<= 100
1 <=N<= 10
1 <=K<= N
1<=A[]<=10
Example:
Input
1
4 2
1 2 3 4
Output
12 
Explanation:
The sub-array of size 2 will be 3 4 and the product is 12.
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:
# You are required to complete this fucntion

# Function should return the an integer

def findMaxProduct(arr, n, m):

    # Code here

Solutions:
import numpy

def findMaxProduct(arr, n, m):
	result = 1
	for i in range(n - m + 1):
		result = max(result, numpy.prod(arr[i:i + m]))
	return result


def findMaxProduct(arr, n, m):
	max_product = 0
	for i in range(n - m + 1):
		product = 1
		for j in range(i, i + m):
			product *= arr[j]
		max_product = max(max_product, product)
	return max_product


def findMaxProduct(arr, n, m):
	maxVal = -1
	for i in range(0, n):
		prd = 1
		start = i
		k = m + start
		while k <= n and start < k:
			prd = prd * arr[start]
			start += 1
		maxVal = max(maxVal, prd)
	return maxVal


def findMaxProduct(arr, n, m):
	max_pro = 1
	for i in range(0, m):
		max_pro *= arr[i]
	prev_pro = max_pro
	for i in range(1, n - m + 1):
		curr_pro = prev_pro // arr[i - 1] * arr[i + m - 1]
		max_pro = max(max_pro, curr_pro)
		prev_pro = curr_pro
	return max_pro


import math

def findMaxProduct(arr, n, m):
	maxi = -math.inf
	for i in range(n - m + 1):
		j = i
		pro = 1
		temp = m
		while temp > 0:
			pro *= arr[j]
			j += 1
			temp -= 1
		maxi = max(maxi, pro)
	return maxi


def findMaxProduct(arr, n, m):
	import numpy as np
	(i, j) = (0, 0)
	maxi = 0
	while j < n:
		if j - i + 1 < m:
			j += 1
		elif j - i + 1 == m:
			maxi = max(maxi, np.prod(arr[i:j + 1]))
			i += 1
			j += 1
	return maxi


def findMaxProduct(arr, n, m):
	prod = 1
	max_prod = 1
	for index in range(n):
		prod *= arr[index]
		if index + 1 >= m:
			max_prod = prod if prod > max_prod else max_prod
			prod = prod // arr[index + 1 - m]
	return max_prod


def findMaxProduct(arr, n, m):
	sum = 0
	a = 1
	for x in range(0, n - (m - 1)):
		for i in range(x, x + m):
			a = a * arr[i]
			if a > sum:
				sum = a
		a = 1
	return sum


def findMaxProduct(arr, n, m):
	res = 0
	for i in range(0, n - m + 1):
		temp = arr[i:i + m]
		prod = 1
		for j in temp:
			prod *= j
		res = max(prod, res)
	return res


def findMaxProduct(arr, n, m):
	product = 1
	for i in range(m):
		product *= arr[i]
	maxi = product
	for i in range(m, n):
		product *= arr[i]
		product //= arr[i - m]
		maxi = max(maxi, product)
	return maxi


import numpy

def findMaxProduct(arr, n, k):
	result = 1
	for i in range(n - k + 1):
		result = max(result, numpy.product(arr[i:i + k]))
	return result


import numpy as np

def findMaxProduct(arr, n, m):
	res = 1
	for i in range(n - m + 1):
		res = max(res, np.prod(arr[i:i + m]))
	return res


def findMaxProduct(arr, n, k):
	prod = 1
	mprod = 1
	for i in range(k):
		prod *= arr[i]
	for i in range(k, n):
		mprod = max(mprod, prod)
		prod *= arr[i]
		prod //= arr[i - k]
	mprod = max(mprod, prod)
	return mprod


def findMaxProduct(arr, n, m):
	all_product = []
	for i in range(n - m + 1):
		new_arr = arr[i:m + i]
		product = 1
		for j in range(m):
			product *= new_arr[j]
		all_product.append(product)
	if all_product != []:
		return max(all_product)
	return -1


def findMaxProduct(arr, n, m):
	prod = 1
	for i in range(0, m, 1):
		prod *= arr[i]
	Max_prod = prod
	for i in range(0, n - m, 1):
		prod //= arr[i]
		prod *= arr[i + m]
		Max_prod = max(Max_prod, prod)
	return Max_prod


def findMaxProduct(arr, n, m):
	i = 0
	out = 0
	while i + m <= n:
		prod = 1
		for j in range(i, i + m):
			prod *= arr[j]
		if prod > out:
			out = prod
		i += 1
	return out


import functools

def findMaxProduct(arr, n, m):
	max_product = 0
	for i in range(0, n - m + 1):
		sub_arr = arr[i:m + i]
		curr_product = functools.reduce(lambda x, y: x * y, sub_arr)
		max_product = curr_product if curr_product > max_product else max_product
	return max_product


def findMaxProduct(arr, n, m):
	MaxProduct = 1
	k = m
	for i in range(0, k):
		MaxProduct = MaxProduct * arr[i]
	prev_product = MaxProduct
	for i in range(1, n - k + 1):
		curr_product = prev_product // arr[i - 1] * arr[i + k - 1]
		MaxProduct = max(MaxProduct, curr_product)
		prev_product = curr_product
	return MaxProduct


def findMaxProduct(arr, n, m):
	pro = 0
	for i in range(n):
		p = 1
		z = arr[i:m + i]
		for i in z:
			p = p * i
		if p > pro:
			pro = p
	return pro


def findMaxProduct(arr, n, m):
	maxProd = 0
	for i in range(n - m + 1):
		prod = 1
		for j in range(m):
			prod *= arr[i + j]
		maxProd = max(maxProd, prod)
	return maxProd


def findMaxProduct(arr, n, m):
	mul = 1
	max_mul = 1
	for index in range(n - m + 1):
		mul = 1
		for elem in arr[index:index + m]:
			mul *= elem
		if mul > max_mul:
			max_mul = mul
	return max_mul


def findMaxProduct(arr, n, m):
	k = []
	for i in range(n - m + 1):
		pro = arr[i]
		for j in range(i + 1, i + m):
			pro = pro * arr[j]
		k.append(pro)
	return max(k)


def sumit(arr, a, b):
	prod = 1
	for i in range(a, b):
		prod *= arr[i]
	return prod

def findMaxProduct(arr, n, m):
	lis = []
	for i in range(n - m + 1):
		lis.append(sumit(arr, i, i + m))
	return max(lis)


def findMaxProduct(arr, n, m):
	mp = 0
	for i in range(0, n, 1):
		mt = 1
		for j in range(i, m + i, 1):
			if i + m - 1 >= n:
				break
			mt = mt * arr[j]
		if mp < mt:
			mp = mt
	return mp


def findMaxProduct(arr, n, k):
	if k > n:
		return -1
	max_product = 1
	product = 1
	for i in range(k):
		product *= arr[i]
	max_product = product
	for i in range(k, n):
		product *= arr[i]
		product //= arr[i - k]
		max_product = max(max_product, product)
	return max_product


def findMaxProduct(arr, n, m):
	max = 0
	for i in range(n):
		L = arr[i:i + m]
		prod = 1
		for j in L:
			prod *= j
		if prod > max:
			max = prod
	return max


def findMaxProduct(arr, n, m):
	count = 0
	m1 = m
	list_product = []
	while n >= m1:
		product = 1
		for i in range(count, m1):
			product *= arr[i]
		list_product.append(product)
		count += 1
		m1 += 1
	max_product = max(list_product)
	return max_product


def findMaxProduct(arr, n, m):
	sum = 1
	max = 0
	for i in range(n - m + 1):
		for j in range(i, i + m):
			sum *= arr[j]
		if sum > max:
			max = sum
		sum = 1
	return max


def prod(arr):
	d = 1
	for ele in arr:
		d = d * ele
	return d

def findMaxProduct(arr, n, m):
	if n == 1:
		return arr[0]
	i = 0
	j = m
	dp = []
	while j < n + 1:
		dp.append(prod(arr[i:j]))
		i += 1
		j += 1
	return max(dp)


def findMaxProduct(arr, n, m):
	product = arr[0]
	for i in range(1, m, 1):
		product *= arr[i]
	max = product
	start = 0
	for i in range(m, n, 1):
		product = int(product / arr[start]) * arr[i]
		start += 1
		if product > max:
			max = product
	return max


import numpy as np

def findMaxProduct(arr, n, m):
	product = 1
	for num in range(n - m + 1):
		product = max(product, np.prod(arr[num:num + m]))
	return product


import numpy
import math

def findMaxProduct(arr, n, m):
	result = -math.inf
	for i in range(0, n - m + 1):
		result = max(result, numpy.prod(arr[i:i + m]))
	return result


def findMaxProduct(arr, n, m):
	max_val = 0
	for i in range(n - m + 1):
		prd_val = arr[i]
		for j in range(m - 1):
			prd_val *= arr[i + j + 1]
		if prd_val > max_val:
			max_val = prd_val
	return max_val


def findMaxProduct(arr, n, m):
	prod = 1
	cnt = m
	j = 0
	for i in range(cnt):
		if j < cnt:
			prod *= arr[i]
			j += 1
	temp = prod
	for i in range(j, len(arr)):
		temp = temp * arr[i] / arr[i - cnt]
		if temp > prod:
			prod = temp
	return int(prod)


def findMaxProduct(arr, n, m):
	import numpy
	product = 0
	prev = 0
	next_ = prev + m
	while next_ <= n:
		p = numpy.prod(arr[prev:next_])
		if p > product:
			product = p
		prev += 1
		next_ = prev + m
	return product


from functools import reduce

def findMaxProduct(arr, n, m):
	pro = 1
	for i in range(n - (m - 1)):
		if pro < reduce(lambda a, b: a * b, arr[i:i + m]):
			pro = reduce(lambda a, b: a * b, arr[i:i + m])
	return pro


def findMaxProduct(arr, n, m):
	import numpy
	p = 0
	i = 0
	j = i + m
	for i in range(n):
		a = numpy.array(arr[i:m + i])
		a = numpy.prod(a)
		if a > p:
			p = a
	return p


def findMaxProduct(arr, n, m):
	x = 0
	for j in range(n - m + 1):
		ans = 1
		for i in range(j, m + j):
			ans *= arr[i]
		if x < ans:
			x = ans
	return x


def findMaxProduct(arr, n, m):
	l = []
	for i in range(0, len(arr) - m + 1):
		f = 1
		for j in arr[i:i + m]:
			f *= j
		l.append(f)
	return max(l)


def findMaxProduct(arr, n, m):
	ans = -1
	for i in range(n):
		prod = 1
		start = i
		k = m + start
		while k <= n and start < k:
			prod *= arr[start]
			start += 1
		ans = max(ans, prod)
	return ans


def findMaxProduct(arr, n, m):
	wstart = 0
	wprod = 1
	mprod = 1
	for wend in range(n):
		wprod = int(wprod * arr[wend])
		if wend >= m - 1:
			mprod = max(mprod, wprod)
			wprod = int(wprod / arr[wstart])
			wstart += 1
	return mprod


def findMaxProduct(arr, n, m):
	result = 1
	ans = 1
	temp = []
	for i in range(n):
		temp = arr[i:i + m]
		for j in temp:
			result *= j
		if result > ans:
			ans = result
		result = 1
	return ans


def findMaxProduct(arr, n, m):
	product = 1
	product1 = 1
	for i in range(n):
		arr1 = arr[i:m + i]
		for j in arr1:
			product = product * j
		if product > product1:
			product1 = product
		product = 1
	return product1


def findMaxProduct(arr, n, m):
	max = 1
	for j in range(n - m + 1):
		temp = 1
		for i in range(j, m + j):
			temp *= arr[i]
		if temp > max:
			max = temp
	return max


def findMaxProduct(arr, n, m):
	ma = float('-inf')
	for i in range(n - m + 1):
		x = 1
		for j in range(i, i + m):
			x = x * arr[j]
		if x > ma:
			ma = x
	return ma


def findMaxProduct(arr, n, k):
	import numpy as np
	subarr = [arr[i] for i in range(k)]
	greatest = np.product(subarr)
	for i in range(k, n):
		subarr.pop(0)
		subarr.append(arr[i])
		current_prod = np.product(subarr)
		if current_prod > greatest:
			greatest = current_prod
		current_prod = 0
	return greatest


def findMaxProduct(arr, n, m):
	max = 0
	for i in range(n - m + 1):
		product = 0
		for j in range(m):
			if j == 0:
				product = arr[i + j]
			else:
				product *= arr[i + j]
		if product > max:
			max = product
	return max


def findMaxProduct(arr, n, m):
	max_prod = 1
	if n == 1 and m == 1:
		return arr[0]
	elif n < m:
		return float('-inf')
	for i in range(n - m + 1):
		curr_prod = 1
		index = 0
		while index < m and i + index < n:
			curr_prod *= arr[i + index]
			index += 1
		if curr_prod > max_prod:
			max_prod = curr_prod
	return max_prod


def findMaxProduct(arr, n, m):
	ANS = 0
	for i in range(n - m + 1):
		ans = 1
		for j in range(i, i + m):
			b = arr[j]
			ans *= b
		if ans > ANS:
			ANS = ans
	return ANS


def findMaxProduct(arr, n, m):
	p = 0
	for j in range(0, n - m + 1):
		s = arr[j:j + m]
		d = 1
		for k in s:
			d = d * k
		if d > p:
			p = d
	return p


def findMaxProduct(arr, n, m):
	M = 0
	for i in range(n - m + 1):
		mult = arr[i]
		for j in range(i + 1, i + m):
			mult = mult * arr[j]
		M = max(M, mult)
	return M


def findMaxProduct(arr, n, m):
	Max = 0
	for i in range(n - m + 1):
		res = 1
		for j in range(m):
			res *= arr[i + j]
		Max = max(Max, res)
	return Max


def findMaxProduct(arr, n, m):
	largest_product = 1
	i = 0
	while i <= len(arr):
		group = arr[i:i + m]
		product = 1
		for j in group:
			product *= j
		if product > largest_product:
			largest_product = product
		i += 1
	return largest_product


def findMaxProduct(arr, n, m):
	maxv = -float('inf')
	ans = 1
	for i in range(m):
		ans *= arr[i]
	s = 1
	e = m
	maxv = ans
	while e < n:
		ans = ans / arr[s - 1] * arr[e]
		s += 1
		e += 1
		maxv = max(maxv, ans)
	return int(maxv)


def findMaxProduct(arr, n, m):
	max_product = 1
	for i in range(n - m + 1):
		curr_product = 1
		for j in range(m):
			curr_product *= arr[i + j]
		if curr_product > max_product:
			max_product = curr_product
	return max_product


def findMaxProduct(arr, n, m):
	prod_arr = []
	k = m
	n_prods = len(arr) - k + 1
	for i in range(n_prods):
		prod = 1
		for j in range(k):
			prod = prod * arr[i + j]
		prod_arr.append(prod)
	return max(prod_arr)


def findMaxProduct(arr, n, m):
	t = 1
	p = 0
	for i in range(n):
		j = i
		while j < n and j - i <= m - 1:
			t = t * arr[j]
			j += 1
		if p < t:
			p = t
		t = 1
	return p


def findMaxProduct(arr, n, m):
	maxs = 0
	for i in range(n - m + 1):
		mul = 1
		for j in range(i, i + m):
			mul = mul * arr[j]
		if mul > maxs:
			maxs = mul
	return maxs


def findMaxProduct(arr, n, m):
	product = 0
	for i in range(n - m + 1):
		curr = 1
		for k in range(m):
			curr *= arr[i + k]
		if curr > product:
			product = curr
	return product


def findMaxProduct(arr, n, m):
	import numpy as np
	pro = 0
	prev = 0
	net = prev + m
	while net <= n:
		p = np.prod(arr[prev:net])
		if p > pro:
			pro = p
		prev += 1
		net = prev + m
	return pro


def findMaxProduct(arr, n, m):
	pro = []
	product = 1
	for i in range(0, m):
		product *= arr[i]
	pro.append(product)
	for i in range(m, n):
		product = product // arr[i - m] * arr[i]
		pro.append(product)
	return max(pro)


def prod(arr):
	product = 1
	for i in range(len(arr)):
		product = product * arr[i]
	return product

def findMaxProduct(arr, n, m):
	start = 0
	end = m
	product = prod(arr[start:end])
	i = 1
	for i in range(1, n - m + 1):
		new_product = prod(arr[i:i + m])
		if new_product > product:
			start = i
			end = i + m
			product = new_product
	return product


def findMaxProduct(arr, n, m):
	maxi = 0
	for x in range(0, n):
		g = arr[x:x + m]
		p = 1
		for x in g:
			p *= x
		if p > maxi:
			maxi = p
	return maxi


from math import inf

def findMaxProduct(a, n, k):
	if k == 0 or n < k:
		return 0
	l = r = 0
	maxP = -inf
	p = 1
	while r < n:
		p *= a[r]
		if l == r - k:
			p //= a[l]
			l += 1
		if r - l + 1 == k:
			maxP = max(maxP, p)
		if p == 0:
			maxP = max(maxP, p)
			l = r + 1
			p = 1
		r += 1
	return maxP


def findMaxProduct(arr, n, k):
	res = curr = 1
	low = 0
	high = 0
	while high < k:
		res = res * arr[high]
		high += 1
	curr = res
	while high < n:
		curr = curr // arr[low]
		curr = curr * arr[high]
		low += 1
		high += 1
		res = max(res, curr)
	return res


def findMaxProduct(arr, n, m):
	max1 = 1
	for i in range(m):
		max1 = max1 * arr[i]
	p = max1
	for i in range(1, n - m + 1):
		curr = p // arr[i - 1] * arr[i + m - 1]
		max1 = max(max1, curr)
		p = curr
	return max1


def findMaxProduct(arr, n, m):
	max = 0
	for i in range(0, n):
		j = i
		temp = 1
		while j < i + m and j < n:
			temp = temp * arr[j]
			j = j + 1
		if temp > max:
			max = temp
	return max


def findMaxProduct(arr, n, m):
	pro = 1
	ans = -1
	for i in range(m):
		pro *= arr[i]
	ans = pro
	for i in range(m, n):
		pro //= arr[i - m]
		pro *= arr[i]
		if pro > ans:
			ans = pro
	return ans


def findMaxProduct(arr, n, k):
	max_prod = 1
	for i in range(n):
		prod = 1
		for j in range(k):
			if i + j < n:
				prod = prod * arr[i + j]
		max_prod = max(prod, max_prod)
	return max_prod


from collections import deque

def findMaxProduct(arr, n, m):
	sum = 1
	value = 1
	for i in range(n - m + 1):
		value = 1
		for j in range(i, i + m):
			value = value * arr[j]
		if value > sum:
			sum = value
	return sum


def findMaxProduct(arr, n, m):
	res = 0
	tich = 1
	for i in range(m):
		tich *= arr[i]
	res = tich
	x = range(m, n)
	for a in x:
		tich = tich // arr[a - m] * arr[a]
		if res < tich:
			res = tich
	return res


def findMaxProduct(arr, n, m):
	maxi = 0
	for i in range(n - m + 1):
		p = 1
		for j in range(i, i + m):
			p *= arr[j]
		if p > maxi:
			maxi = p
	return maxi