Maximum number of given operations to remove the entire string | Function to return the maximum number of given operations required to remove the given entirely ; If length of the 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 subs [ 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 subs [ i + 1. . . n - 1 ] ; Entire has to be deleted ; Driver code
def find ( s ) : NEW_LINE INDENT if ( len ( s ) == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT c = 1 NEW_LINE d = " " NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT d += s [ i ] NEW_LINE s2 = s [ i + 1 : i + 1 + len ( d ) ] NEW_LINE if ( s2 == d ) : NEW_LINE INDENT c = 1 + find ( s [ i + 1 : ] ) NEW_LINE break NEW_LINE DEDENT DEDENT return c NEW_LINE DEDENT s = " abababab " NEW_LINE print ( find ( s ) ) NEW_LINE