Maximum String Partition | Return the count of string ; P will store the answer ; Current will store current string Previous will store the previous that has been taken already ; Add a character to current string ; Here we will create a partition and update the previous with current string ; Now we will clear the current string ; Increment the count of partition . ; Driver code
def maxPartition ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE P = 0 NEW_LINE current = " " NEW_LINE previous = " " NEW_LINE for i in range ( n ) : NEW_LINE INDENT current += s [ i ] NEW_LINE if ( current != previous ) : NEW_LINE INDENT previous = current NEW_LINE current = " " NEW_LINE P += 1 NEW_LINE DEDENT DEDENT return P NEW_LINE DEDENT s = " geeksforgeeks " NEW_LINE ans = maxPartition ( s ) NEW_LINE print ( ans ) NEW_LINE