Longest subarray in which all elements are smaller than K | Function to find the length of the longest subarray with all elements smaller than K ; Stores the length of maximum consecutive sequence ; Stores maximum length of subarray ; Iterate through the array ; Check if array element smaller than K ; Store the maximum of length and count ; Reset the counter ; Prlet the maximum length ; Given array arr [ ] ; Size of the array ; Given K ; Function Call
function largestSubarray ( arr , N , K ) { let count = 0 ; let len = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < K ) { count += 1 ; } else { len = Math . max ( len , count ) ; count = 0 ; } } if ( count != 0 ) { len = Math . max ( len , count ) ; } document . write ( len ) ; } let arr = [ 1 , 8 , 3 , 5 , 2 , 2 , 1 , 13 ] ; let N = arr . length ; let K = 6 ; largestSubarray ( arr , N , K ) ;