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
function isAutoBiographyNum ( number ) { let count = 0 , position , size , digit ; let NUM ; NUM = number . toString ( ) ; size = NUM . length ; for ( let i = 0 ; i < size ; i ++ ) { position = NUM [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; count = 0 ; for ( let j = 0 ; j < size ; j ++ ) { digit = NUM [ j ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; if ( digit == i ) count ++ ; } if ( position != count ) return false ; } return true ; } function checkArray ( arr , n ) { let current_length = 0 ; let max_length = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isAutoBiographyNum ( arr [ i ] ) ) current_length ++ ; else current_length = 0 ; max_length = Math . max ( max_length , current_length ) ; } return max_length ; } let arr = [ 21200 , 1 , 1303 , 1210 , 2020 ] ; let n = arr . length ; document . write ( checkArray ( arr , n ) ) ;