Longest subarray with elements divisible by k | function to find longest subarray ; this will contain length of longest subarray found ;
function longestsubarray ( arr , n , k ) { let current_count = 0 ; let max_count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) current_count ++ ; else current_count = 0 ; max_count = Math . max ( current_count , max_count ) ; } return max_count ; } let arr = [ 2 , 5 , 11 , 32 , 64 , 88 ] ; let n = arr . length ; let k = 8 ; document . write ( longestsubarray ( arr , n , k ) ) ;