A Function to find the string having the minimum length and returns that length
static int findMinLength ( String arr [ ] , int n ) { int min = Integer . MAX_VALUE ; for ( int i = 0 ; i <= ( n - 1 ) ; i ++ ) { if ( arr [ i ] . length ( ) < min ) { min = arr [ i ] . length ( ) ; } } return min ; } static boolean allContainsPrefix ( String arr [ ] , int n , String str , int start , int end ) { for ( int i = 0 ; i <= ( n - 1 ) ; i ++ ) { String arr_i = arr [ i ] ; for ( int j = start ; j <= end ; j ++ ) if ( arr_i . charAt ( j ) != str . charAt ( j ) ) return false ; } return true ; }