Maximum power of jump required to reach the end of string | Function to calculate the maximum power of the jump ; Initialize the count with 1 ; Find the character at last index ; Start traversing the string ; Check if the current char is equal to the last character ; max_so_far stores maximum value of the power of the jump from starting to ith position ; Reset the count to 1 ; Else , increment the number of jumps / count ; Return the maximum number of jumps ; Driver code
< ? php function powerOfJump ( $ s ) { $ count = 1 ; $ max_so_far = PHP_INT_MIN ; $ ch = $ s [ strlen ( $ s ) - 1 ] ; for ( $ i = 0 ; $ i < strlen ( $ s ) ; $ i ++ ) { if ( $ s [ $ i ] == $ ch ) { if ( $ count > $ max_so_far ) { $ max_so_far = $ count ; } $ count = 1 ; } else $ count ++ ; } return $ max_so_far ; } $ st = "1010101" ; echo powerOfJump ( $ st ) ; ? >