Find the length of largest subarray in which all elements are Autobiographical Numbers | Java program to find the length of the largest subarray whose every element is an autobiographical number ; 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
class GFG { static boolean isAutoBiographyNum ( int number ) { int count = 0 , position , size , digit ; String NUM ; NUM = Integer . toString ( number ) ; size = NUM . length ( ) ; for ( int i = 0 ; i < size ; i ++ ) { position = NUM . charAt ( i ) - '0' ; count = 0 ; for ( int j = 0 ; j < size ; j ++ ) { digit = NUM . charAt ( j ) - '0' ; if ( digit == i ) count ++ ; } if ( position != count ) return false ; } return true ; } static int checkArray ( int arr [ ] , int n ) { int current_length = 0 ; int max_length = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isAutoBiographyNum ( arr [ i ] ) == true ) { current_length ++ ; } else { current_length = 0 ; } max_length = Math . max ( max_length , current_length ) ; } return max_length ; } public static void main ( String [ ] args ) { int arr [ ] = { 21200 , 1 , 1303 , 1210 , 2020 } ; int n = arr . length ; System . out . println ( checkArray ( arr , n ) ) ; } }