human
Find all possible subarrays having product less than or equal to K | Function to return all possible subarrays having product less than or equal to K.
Store the required subarrays.
Stores the product of current subarray.
Stores the starting index of the current subarray.
Check for empty array.
Iterate over the array.
Calculate product.
If product exceeds K.
Reduce product.
Increase starting index of current subarray.
Stores the subarray elements.
Store the subarray elements.
Add the subarrays to the li.
Return the final li of subarrays.
Driver Code"
Solution in Python:
 Write me a code to find all possible subarrays having product less than or equal to K and the other steps required?
assistant
#Here is code to find all possible subarrays having product less than or equal to K and the other steps required.
 def maxSubArray ( arr , n , K ) :
	solution = [ ]
	multi = 1
	start = 0
	if ( n <= 1 or K < 0 ) :
		return solution
	for i in range ( n ) :
		multi = multi * arr [ i ]
		while ( multi > K ) :
			multi = multi // arr [ start ]
			start += 1
		li = [ ]
		j = i
		while ( j >= start ) :
			li . insert ( 0 , arr [ j ] )
			solution . append ( list ( li ) )
			j -= 1
	return solution
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 7 , 1 , 4 ]
	n = len ( arr )
	K = 7
	v = maxSubArray ( arr , n , K )
	print ( v )