human
Length of longest subarray whose sum is not divisible by integer K | Function to find the longest subarray with sum is not divisible by k.
left is the index of the leftmost element that is not divisible by k.
sum of the array.
Find the element that is not multiple of k.
left = - 1 means we are finding the leftmost element that is not divisible by k.
Updating the rightmost element.
Update the sum of the array up to the index i.
Check if the sum of the array is not divisible by k , then return the size of array.
All elements of array are divisible by k , then no such subarray possible so return - 1.
length of prefix elements that can be removed.
length of suffix elements that can be removed.
Return the length of subarray after removing the elements which have lesser number of elements.
Driver Code"
How can the above be solved in Python?

=====
Give me a code to length of longest subarray whose sum is not divisible by integer K and the other steps required?
assistant
#Here is code to length of longest subarray whose sum is not divisible by integer K and the other steps required.
 def MaxSubarrayLength ( arr , n , k ) :
	left = - 1
	sum = 0
	for i in range ( n ) :
		if ( ( arr [ i ] % k ) != 0 ) :
			if ( left == - 1 ) :
				left = i
			right = i
		sum += arr [ i ]
	if ( ( sum % k ) != 0 ) :
		return n
	elif ( left == - 1 ) :
		return - 1
	else :
		prefix_length = left + 1
		suffix_length = n - right
		return n - min ( prefix_length , suffix_length )
if __name__ == " _ _ main _ _ " :
	arr = [ 6 , 3 , 12 , 15 ]
	n = len ( arr )
	K = 3
	print ( MaxSubarrayLength ( arr , n , K ) )