Longest subarray with elements divisible by k | function to find longest subarray ; this will contain length of longest subarray found ; Driver code
def longestsubarray ( arr , n , k ) : NEW_LINE INDENT current_count = 0 NEW_LINE max_count = 0 NEW_LINE for i in range ( 0 , n , 1 ) : NEW_LINE INDENT if ( arr [ i ] % k == 0 ) : NEW_LINE INDENT current_count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT current_count = 0 NEW_LINE DEDENT max_count = max ( current_count , max_count ) NEW_LINE DEDENT return max_count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 5 , 11 , 32 , 64 , 88 ] NEW_LINE n = len ( arr ) NEW_LINE k = 8 NEW_LINE print ( longestsubarray ( arr , n , k ) ) NEW_LINE DEDENT