Split a string into maximum number of unique substrings | Utility function to find maximum count of unique substrings by splitting the string ; Stores maximum count of unique substring by splitting the string into substrings ; Iterate over the characters of the string ; Stores prefix substring ; Check if the current substring already exists ; Insert tmp into set ; Recursively call for remaining characters of string ; Remove from the set ; Return answer ; Function to find the maximum count of unique substrings by splitting a string into maximum number of unique substrings ; Driver Code
function maxUnique ( S , st ) { var mx = 0 ; for ( var i = 1 ; i <= S . length ; i ++ ) { var tmp = S . substring ( 0 , i ) ; if ( ! st . has ( tmp ) ) { st . add ( tmp ) ; mx = Math . max ( mx , maxUnique ( S . substring ( i ) , st ) + 1 ) ; st . delete ( tmp ) ; } } return mx ; } function maxUniqueSplit ( S ) { var st = new Set ( ) ; return maxUnique ( S , st ) ; } var S = " " ; var res = maxUniqueSplit ( S ) ; document . write ( res ) ;