Find the length of largest subarray in which all elements are Autobiographical Numbers | Function to check number is autobiographical ; Convert integer to string ; Iterate for every digit to check for their total count ; Check occurrence of every number and count them ; Check if any position mismatches with total count them return with false else continue with loop ; Function to return the length of the largest subarray whose every element is a autobiographical number ; Utility function which checks every element of array for autobiographical number ; Check if element arr [ i ] is an autobiographical number ; Increment the current length ; Update max_length value ; Return the final result ; Driver code
def isAutoBiographyNum ( number ) : NEW_LINE INDENT count = 0 ; NEW_LINE NUM = str ( number ) ; NEW_LINE size = len ( NUM ) ; NEW_LINE for i in range ( size ) : NEW_LINE INDENT position = ord ( NUM [ i ] ) - ord ( '0' ) ; NEW_LINE count = 0 ; NEW_LINE for j in range ( size ) : NEW_LINE INDENT digit = ord ( NUM [ j ] ) - ord ( '0' ) ; NEW_LINE if ( digit == i ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT if ( position != count ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT def checkArray ( arr , n ) : NEW_LINE INDENT current_length = 0 ; NEW_LINE max_length = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( isAutoBiographyNum ( arr [ i ] ) ) : NEW_LINE INDENT current_length += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT current_length = 0 ; NEW_LINE DEDENT max_length = max ( max_length , current_length ) ; NEW_LINE DEDENT return max_length ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 21200 , 1 , 1303 , 1210 , 2020 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( checkArray ( arr , n ) ) ; NEW_LINE DEDENT