human
Give me a code to subarray with no pair sum divisible by K and the other steps required given the following:
Subarray with no pair sum divisible by K | function to find the subarray with no pair sum divisible by k.
hash table to store the remainders obtained on dividing by K.
s : starting index of the current subarray , e : ending index of the current subarray , maxs : starting index of the maximum size subarray so far , maxe : ending index of the maximum size subarray so far.
insert the first element in the set.
Removing starting elements of current subarray while there is an element in set which makes a pair with mod [ i ] such that the pair sum is divisible ..
include the current element in the current subarray the ending index of the current subarray increments by one.
compare the size of the current subarray with the maximum size so far.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to subarray with no pair sum divisible by K and the other steps required.
 def subarrayDivisibleByK ( arr , n , k ) :
	mp = [ 0 ] * 1000
	s = 0 ; e = 0 ; maxs = 0 ; maxe = 0 ;
	mp [ arr [ 0 ] % k ] = mp [ arr [ 0 ] % k ] + 1 ;
	for i in range ( 1 , n ) :
		mod = arr [ i ] % k
		while ( mp [ k - mod ] != 0 or ( mod == 0 and mp [ mod ] != 0 ) ) :
			mp [ arr [ s ] % k ] = mp [ arr [ s ] % k ] - 1
			s = s + 1
		mp [ mod ] = mp [ mod ] + 1
		e = e + 1
		if ( ( e - s ) > ( maxe - maxs ) ) :
			maxe = e
			maxs = s
	print ( " The ▁ maximum ▁ size ▁ is ▁ { } ▁ and ▁ the ▁ " . format ( ( maxe - maxs + 1 ) ) ) for i in range ( maxs , maxe + 1 ) :
		print ( " { } ▁ " . format ( arr [ i ] ) , end = " " )
k = 3
arr = [ 5 , 10 , 15 , 20 , 25 ]
n = len ( arr )
subarrayDivisibleByK ( arr , n , k )