Maximum String Partition | Return the count of string ; P will store the answer ; Current will store current string Previous will store the previous string that has been taken already ; Add a character to current string ; Here we will create a partition and update the previous string with current string ; Now we will clear the current string ; Increment the count of partition . ; Driver code
function maxPartition ( s ) { var n = s . length , P = 0 ; var current = " " , previous = " " ; for ( var i = 0 ; i < n ; i ++ ) { current += s [ i ] ; if ( current != previous ) { previous = current ; current = " " ; P ++ ; } } return P ; } var s = " " ; var ans = maxPartition ( s ) ; document . write ( ans ) ;