Maximum number of given operations to remove the entire string | Function to return the maximum number of given operations required to remove the given string entirely ; If length of the string is zero ; Single operation can delete the entire string ; To store the prefix of the string which is to be deleted ; Prefix s [ 0. . i ] ; To store the substring s [ i + 1. . .2 * i + 1 ] ; If the prefix s [ 0. . . i ] can be deleted ; 1 operation to remove the current prefix and then recursively find the count of operations for the substring s [ i + 1. . . n - 1 ] ; Entire string has to be deleted ; Driver code
function find ( s ) { if ( s . length == 0 ) return 0 ; var c = 1 ; var d = " " ; for ( var i = 0 ; i < s . length ; i ++ ) { d += s [ i ] ; var s2 = s . substring ( i + 1 , i + 1 + d . length ) ; if ( s2 == d ) { c = 1 + find ( s . substring ( i + 1 ) ) ; break ; } } return c ; } var s = " " ; document . write ( find ( s ) ) ;