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 ; Print the maximum length ; Driver Code ; Given array arr [ ] ; Size of the array ; Given K ; Function Call
def largestSubarray ( arr , N , K ) : NEW_LINE INDENT count = 0 NEW_LINE length = 0 NEW_LINE for i in range ( N ) : NEW_LINE if ( arr [ i ] < K ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT length = max ( length , count ) NEW_LINE count = 0 NEW_LINE DEDENT if ( count ) : NEW_LINE INDENT length = max ( length , count ) NEW_LINE DEDENT print ( length , end = " " ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 8 , 3 , 5 , 2 , 2 , 1 , 13 ] NEW_LINE N = len ( arr ) NEW_LINE K = 6 NEW_LINE largestSubarray ( arr , N , K ) NEW_LINE DEDENT