Largest substring with same Characters | Function to find largest sub string with same characters ; Traverse the string ; If character is same as previous increment temp value ; Return the required answer ; Driver code ; Function call
< ? php function Substring ( $ s ) { $ ans = 1 ; $ temp = 1 ; for ( $ i = 1 ; $ i < strlen ( $ s ) ; $ i ++ ) { if ( $ s [ $ i ] == $ s [ $ i - 1 ] ) { ++ $ temp ; } else { $ ans = max ( $ ans , $ temp ) ; $ temp = 1 ; } } $ ans = max ( $ ans , $ temp ) ; return $ ans ; } $ s = " abcdddddeff " ; echo Substring ( $ s ) ; ? >