codeparrot/xlcost-text-to-code huggingface dataset:
Minimize flips to make binary string as all 1 s by flipping characters in substring of size K repeatedly | Function to find the minimum number of operations required to convert all the characters to 1 by flipping the substrings of size K ; Stores the minimum number of operations required ; Traverse the string S ; If the character is 0 ; Flip the substrings of size K starting from i ; Increment the minimum count of operations required ; After performing the operations check if string S contains any 0 s ; If S contains only 1 's ; Driver Code
function minOperation ( St , K , N ) { S = St . split ( ' ' ) ; let min = 0 ; let i ; for ( i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' ' && i + K <= N ) { for ( let j = i ; j < i + K ; j ++ ) { if ( S [ j ] == ' ' ) S [ j ] = ' ' ; else S [ j ] = ' ' ; } min ++ ; } } for ( i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' ' ) break ; } if ( i == N ) document . write ( min ) ; else document . write ( - 1 ) ; } let S = " " ; let K = 3 ; let N = S . length ; minOperation ( S , K , N ) ;
Check if string S1 can be formed using repeated insertions of another string S2 | Function to check a valid insertion ; Store the size of string ; Maintain a stack for characters ; Iterate through the string ; push the current character on top of the stack ; If the current character is the last character of string S2 then pop characters until S2 is not formed ; index of last character of the string S2 ; pop characters till 0 - th index ; Check if stack in non - empty ; Driver Code
function validInsertionstring ( S1 , S2 ) { let N = S1 . length ; let M = S2 . length ; let st = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { st . push ( S1 [ i ] ) ; if ( S1 [ i ] == S2 [ M - 1 ] ) { let idx = M - 1 ; while ( idx >= 0 ) { if ( st . length == 0 ) { return false ; } let c = st [ st . length - 1 ] ; st . pop ( ) ; if ( c != S2 [ idx ] ) { return false ; } idx -- ; } } } if ( st . length != 0 ) { return false ; } else { return true ; } } let S1 = " " ; let S2 = " " ; validInsertionstring ( S1 , S2 ) ? document . write ( " " ) : document . write ( " " ) ;
Check if rearranging Array elements can form a Palindrome or not | JavaScript Program to implement the above approach ; Function to check whether elements of an array can form a palindrome ; create an empty string to append elements of an array ; append each element to the string str to form a string so that we can solve it in easy way ; Create a freq array and initialize all values as 0 ; For each character in formed string , increment freq in the corresponding freq array ; Count odd occurring characters ; Return true if odd count is 0 or 1 , ; Drive code
let MAX = 256 function can_form_palindrome ( arr , n ) { let str = " " ; for ( let i = 0 ; i < n ; i ++ ) { str += toString ( arr [ i ] ) ; } let freq = new Array ( n ) . fill ( 0 ) ; for ( let i = 0 ; i < str . length ; i ++ ) { freq [ str . charCodeAt ( i ) ] ++ ; } let count = 0 ; for ( let i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] & 1 ) { count ++ ; } if ( count > 1 ) { return false ; } } return true ; } let arr = [ 1 , 2 , 3 , 1 , 2 ] ; let n = arr . length ; can_form_palindrome ( arr , n ) ? document . write ( " " ) : document . write ( " " ) ;
Minimum number of flips to make a Binary String increasing | Function to find the minimum number of flips required to make string increasing ; Length of s ; Total number of zero in s ; Stores count of 1 s till ith index ; Stores the minimum count of flips ; Traverse the given string S ; Update the value of res and count of 1 s ; Return the minimum number of flips ; Given String ; Function Call
function minimumFlips ( s ) { let n = s . length ; let i ; let cnt0 = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) cnt0 ++ ; } let cnt1 = 0 let res = n - cnt0 for ( i = 0 ; i < n ; i ++ ) if ( s [ i ] == ' ' ) { cnt0 -= 1 } else if ( s [ i ] == ' ' ) { res = Math . min ( res , cnt1 + cnt0 ) cnt1 += 1 } return res } S = ' ' document . write ( minimumFlips ( S ) )
Lexicographically shortest string of length at most K which is not a substring of given String | Function to return a set of all substrings of given string which have length less than or equal to k ; Function to print the lexicographically smallest substring of length atmost k which is not present in given string s ; All substrings of length atmost k present in string s are stored in this set ; Loop to change length of substring ; String with length = len which has all characters as ' a ' ; If the substrings set does not contain this string then we have found the answer ; Changing the likes of ' azz ' and ' daz ' to ' baa ' and ' dba ' respectively ; Reached a string like ' zz ' or ' zzz ' increase the length of the substring ; Given Input ; Function Call
function presentSubstring ( s , k ) { let st = new Set ( ) ; let n = s . length ; s = s . split ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) { let s1 = " " ; for ( let j = 0 ; j < k && i + j < n ; j ++ ) { s1 += s [ i + j ] ; st . add ( s1 ) ; } } return st ; } function smallestSubstring ( s , k ) { let st = new Set ( ) ; st = presentSubstring ( s , k ) ; let index = 0 ; for ( let len = 1 ; len <= k ; len ++ ) { let t = new Array ( len ) . fill ( " " ) ; while ( true ) { if ( ! st . has ( t . join ( " " ) ) ) { return t . join ( " " ) ; } index = len - 1 ; while ( index >= 0 && t [ index ] == " " ) { t [ index ] = " " ; index -- ; } if ( index >= 0 ) t [ index ] = String . fromCharCode ( t [ index ] . charCodeAt ( 0 ) + 1 ) ; else break ; } } return " " ; } let s = " " ; let K = 3 ; document . write ( smallestSubstring ( s , K ) ) ;
Maximum length of a substring required to be flipped repeatedly to make all characters of binary string equal to 0 | Function to find the maximum value of K such that flipping substrings of size at least K make all characters 0 s ; Stores the maximum value of K ; Traverse the given string S ; Store the minimum of the maximum of LHS and RHS length ; Flip performed ; If no flips performed ; Return the possible value of K ; Driver Code
function maximumK ( S ) { let N = S . length ; let ans = N ; let flag = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( S [ i ] != S [ i + 1 ] ) { flag = 1 ; ans = Math . min ( ans , Math . max ( i + 1 , N - i - 1 ) ) ; } } if ( flag == 0 ) return 0 ; return ans ; } let S = " " ; document . write ( maximumK ( S ) ) ;
Check if a pair of strings exists that starts with and without the character K or not | Function to check whether a pair of strings exists satisfying the conditions ; Stores the visited strings ; Iterate over the array arr [ ] ; If first character of current string is K ; Otherwise ; Adding to the visited ; Given Input
function checkhappy ( arr , K , N ) { let visited = new Set ( ) ; for ( let s of arr ) { if ( s [ 0 ] == K ) { if ( visited . has ( s . slice ( 1 ) ) ) return " " ; } else { if ( visited . has ( K + s ) ) return " " ; } visited . add ( s ) ; } return " " ; } let arr = [ " " , " " , " " , " " , " " , " " ] ; let K = " " ; let N = arr . length ; document . write ( checkhappy ( arr , K , N ) ) ;
Minimum moves to make count of lowercase and uppercase letters equal | Function to calculate minimum number of moves required to convert the string ; Stores Count of upper and lower case characters ; Traverse the string S ; If current character is uppercase ; Increment count of Uppercase characters ; Otherwise , ; Increment count of Lowercase characters ; Stores minimum number of moves needed ; If there are more upper case characters ; Iterate until upper is greater than N / 2 ; Convert uppercase into lowercase until upper = N / 2 ; Increment the pointer ; If there are more lower case characters ; Iterate until lower is greater than N / 2 ; Convert lowercase into uppercase until lower = N / 2 ; Increment the pointer ; Print moves required ; Print resultant string ; Given string ; Function call
function minimumTimeToConvertString ( S , N ) { let upper = 0 , lower = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let c = S [ i ] ; if ( c == c . toUpperCase ( ) ) { upper ++ ; } else { lower ++ ; } } let moves = 0 ; if ( upper > parseInt ( N / 2 , 10 ) ) { let i = 0 ; while ( upper > parseInt ( N / 2 , 10 ) && i < N ) { if ( S [ i ] == S [ i ] . toUpperCase ( ) ) { S [ i ] += String . fromCharCode ( 32 ) ; moves ++ ; upper -- ; lower ++ ; } i ++ ; } } else if ( lower > parseInt ( N / 2 , 10 ) ) { let i = 0 ; while ( lower > parseInt ( N / 2 , 10 ) && i < N ) { if ( S [ i ] == S [ i ] . toLowerCase ( ) ) { S [ i ] = String . fromCharCode ( S [ i ] . charCodeAt ( ) - 32 ) ; moves ++ ; upper ++ ; lower -- ; } i ++ ; } } document . write ( moves + " " ) ; document . write ( S . join ( " " ) ) ; } let S = " " ; let N = S . length ; minimumTimeToConvertString ( S . split ( ' ' ) , N ) ;
Program to print a string in vertical zigzag manner | Function to print any string in zigzag fashion ; Store the gap between the major columns ; Traverse through rows ; Store the step value for each row ; Iterate in the range [ 1 , N - 1 ] ; Print the character ; Print the spaces before character s [ j + step ] ; Print the character ; Print the spaces after character after s [ j + step ] ; Print the spaces for first and last rows ; Given Input ; Function Call
function zigzag ( s , rows ) { let interval = 2 * rows - 2 ; for ( let i = 0 ; i < rows ; i ++ ) { let step = interval - 2 * i ; for ( let j = i ; j < s . length ; j = j + interval ) { document . write ( s [ j ] ) ; if ( step > 0 && step < interval && step + j < s . length ) { for ( let k = 0 ; k < ( interval - rows - i ) ; k ++ ) document . write ( " " ) ; document . write ( s [ j + step ] ) ; for ( let k = 0 ; k < i - 1 ; k ++ ) document . write ( " " ) ; } else { for ( let k = 0 ; k < ( interval - rows ) ; k ++ ) document . write ( " " ) ; } } document . write ( " " ) ; } } let s = " " + " " + " " ; let rows = 9 ; zigzag ( s , rows ) ;
Number of substrings with each character occurring even times | Function to count substrings having even frequency of each character ; Stores the count of a character ; Stores bitmask ; Stores the count of substrings with even count of each character ; Traverse the string S ; Flip the ord ( i ) - 97 bits in pre ; Increment the count by hash [ pre ] ; Increment count of pre in hash ; Return the total count obtained ; Driver code
function subString ( s , n ) { let hash = new Map ( ) ; hash . set ( 0 , 1 ) ; let pre = 0 ; let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { pre ^= ( 1 << s [ i ] . charCodeAt ( 0 ) - 97 ) ; if ( ! hash . has ( pre ) ) hash . set ( pre , 0 ) ; count += ( hash . get ( pre ) ) ; hash . set ( pre , hash . get ( pre ) == null ? 0 : hash . get ( pre ) + 1 ) ; } return count ; } let S = " " ; let N = S . length ; document . write ( subString ( S , N ) ) ;
Count number of substrings having at least K distinct characters | Function to count number of substrings having atleast k distinct characters ; Stores the size of the string ; Initialize a HashMap ; Stores the start and end indices of sliding window ; Stores the required result ; Iterate while the end pointer is less than n ; Include the character at the end of the window ; Increment end pointer by 1 ; Iterate until count of distinct characters becomes less than K ; Remove the character from the beginning of window ; If its frequency is 0 , remove it from the map ; Update the answer ; Print the result ; Driver Code
function atleastkDistinctChars ( s , k ) { let n = s . length ; let mp = new Map ( ) ; let begin = 0 , end = 0 ; let ans = 0 ; while ( end < n ) { let c = s [ end ] ; if ( mp . has ( c ) ) mp . set ( c , mp . get ( c ) + 1 ) ; else mp . set ( c , 1 ) ; end ++ ; while ( mp . size >= k ) { let pre = s [ begin ] ; mp . set ( pre , mp . get ( pre ) - 1 ) ; if ( mp . get ( pre ) == 0 ) { mp . delete ( pre ) ; } ans += s . length - end + 1 ; begin ++ ; } } document . write ( ans ) ; } let S = " " ; let K = 3 ; atleastkDistinctChars ( S , K ) ;
Rearrange characters of a string to make it a concatenation of palindromic substrings | Function to check if a string can be modified such that it can be split into palindromic substrings of length >= 2 ; Stores frequencies of characters ; Traverse the string ; Update frequency of each character ; Traverse the frequency array ; Update values of odd and eve ; Print the result ; Driver Code
function canSplit ( S ) { let frequency = new Array ( 26 ) . fill ( 0 ) let cnt_singles = 0 let k = 0 for ( let i = 0 ; i < S . length ; i ++ ) { frequency [ S . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ] += 1 } let odd = 0 let eve = 0 for ( let i = 0 ; i < 26 ; i ++ ) { if ( frequency [ i ] ) { odd += ( frequency [ i ] & 1 ) } } if ( eve >= odd ) { document . write ( " " ) } else { document . write ( " " ) } } let S = " " canSplit ( S )
Maximize count of occurrences of S2 in S1 as a subsequence by concatenating N1 and N2 times respectively | Function to count maximum number of occurrences of s2 as subsequence in s1 by concatenating s1 , n1 times and s2 , n2 times ; Stores number of times s1 is traversed ; Stores number of times s2 is traversed ; Mapping index of s2 to number of times s1 and s2 are traversed ; Stores index of s1 circularly ; Stores index of s2 circularly ; Traverse the string s1 , n1 times ; If current character of both the string are equal ; Update j ; Update i ; If j is length of s2 ; Update j for circular traversal ; Update s2_reps ; If i is length of s1 ; Update i for circular traversal ; Update s1_reps ; If already mapped j to ( s1_reps , s2_reps ) ; Mapping j to ( s1_reps , s2_reps ) ; If s1 already traversed n1 times ; Otherwis , traverse string s1 by multiple of s1_reps and update both s1_reps and s2_reps ; Update s2_reps ; Update s1_reps ; If s1 is traversed less than n1 times ; If current character in both the string are equal ; Update j ; Update i ; If i is length of s1 ; Update i for circular traversal ; Update s1_reps ; If j is length of ss ; Update j for circular traversal ; Update s2_reps ; Driver Code
function getMaxRepetitions ( s1 , n1 , s2 , n2 ) { let temp1 = new Array ( 26 ) ; let temp2 = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { temp1 [ i ] = 0 ; temp2 [ i ] = 0 ; } for ( let i = 0 ; i < s1 . split ( " " ) . length ; i ++ ) temp1 [ s1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < s2 . split ( " " ) . length ; i ++ ) temp2 [ s2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( temp2 [ i ] > temp1 [ i ] ) return 0 ; } let s1_reps = 0 ; let s2_reps = 0 ; let s2_index_to_reps = new Map ( ) ; s2_index_to_reps . set ( 0 , [ 0 , 0 ] ) ; let i = 0 ; let j = 0 ; while ( s1_reps < n1 ) { if ( s1 [ i ] == s2 [ j ] ) j += 1 ; i += 1 ; if ( j == s2 . length ) { j = 0 ; s2_reps += 1 ; } if ( i == s1 . length ) { i = 0 ; s1_reps += 1 ; if ( ! s2_index_to_reps . has ( j ) ) break ; s2_index_to_reps . set ( j , [ s1_reps , s2_reps ] ) ; } } if ( s1_reps == n1 ) return s2_reps / n2 ; let initial_s1_reps = s2_index_to_reps . get ( j ) [ 0 ] , initial_s2_reps = s2_index_to_reps . get ( j ) [ 1 ] ; let loop_s1_reps = s1_reps - initial_s1_reps ; let loop_s2_reps = s2_reps - initial_s2_reps ; let loops = ( n1 - initial_s1_reps ) ; s2_reps = initial_s2_reps + loops * loop_s2_reps ; s1_reps = initial_s1_reps + loops * loop_s1_reps ; while ( s1_reps < n1 ) { if ( s1 [ i ] == s2 [ j ] ) j += 1 ; i += 1 ; if ( i == s1 . length ) { i = 0 ; s1_reps += 1 ; } if ( j == s2 . length ) { j = 0 ; s2_reps += 1 ; } } return s2_reps / n2 ; } let s1 = " " ; let n1 = 4 ; let s2 = " " ; let n2 = 2 ; document . write ( getMaxRepetitions ( s1 , n1 , s2 , n2 ) ) ;
Shortest string possible after removal of all pairs of similar adjacent characters | Function to delete pair of adjacent characters which are equal ; Base Case ; Stores the update string ; Traverse the string s ; If two unequal pair of adjacent characters are found ; If two equal pair of adjacent characters are found ; Append the remaining string after removing the pair ; Return the final String ; Function to find the shortest string after repeatedly removing pairs of adjacent characters which are equal ; Stores the resultant String ; Keeps track of previously iterated string ; Update the result after deleting adjacent pair of characters which are similar ; Termination Conditions ; Update pre variable with the value of result ; Case for " Empty ▁ String " ; Driver Code
function removeAdjacent ( s ) { if ( s . length == 1 ) return s ; let sb = " " ; for ( let i = 0 ; i < s . length - 1 ; i ++ ) { let c = s [ i ] ; let d = s [ i + 1 ] ; if ( c != d ) { sb = sb + c ; if ( i == s . length - 2 ) { sb = sb + d ; } } else { for ( let j = i + 2 ; j < s . length ; j ++ ) sb = sb + s [ j ] ; return sb ; } } return sb ; } function reduceString ( s ) { let result = " " ; let pre = s ; while ( true ) { result = removeAdjacent ( pre ) ; if ( result == pre ) break ; pre = result ; } if ( result . length != 0 ) document . write ( result ) ; else document . write ( " " ) ; } let S = " " ; reduceString ( S ) ;
Minimum removals required such that a string can be rearranged to form a palindrome | Function to find the number of deletions required such that characters of the string can be rearranged to form a palindrome ; Stores frequency of characters ; Store the frequency of each character in frequency array ; let a = parseInt ( str [ i ] - 97 ) ; ; Count number of characters with odd frequency ; If count is 1 or 0 , return 0 ; Otherwise , return count - 1 ; Function call to find minimum number of deletions required
function minDeletions ( str ) { var fre = new Array ( 26 ) ; fre . fill ( 0 ) ; var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) { fre [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; } var count = 0 ; for ( var i = 0 ; i < 26 ; i ++ ) { if ( fre [ i ] % 2 ) { count += 1 ; } } if ( count == 0 count == 1 ) { return 0 ; } else { return count - 1 ; } } var str = " " ; document . write ( minDeletions ( str ) + " " ) ;
Program to print an array in Pendulum Arrangement | Prints pendulam arrangement of arr [ ] ; sorting the elements ; Auxiliary array to store output ; calculating the middle index ; storing the minimum element in the middle i is index for output array and j is for input array . ; adjustment for when no . of elements is even ; Printing the pendulum arrangement ; input Array ; calculating the length of array A ; calling pendulum function
function pendulumArrangement ( arr , n ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; var op = [ ... Array ( n ) ] ; var mid = parseInt ( ( n - 1 ) / 2 ) ; var j = 1 , i = 1 ; op [ mid ] = arr [ 0 ] ; for ( i = 1 ; i <= mid ; i ++ ) { op [ mid + i ] = arr [ j ++ ] ; op [ mid - i ] = arr [ j ++ ] ; } if ( n % 2 == 0 ) op [ mid + i ] = arr [ j ] ; document . write ( " " ) ; for ( i = 0 ; i < n ; i ++ ) document . write ( op [ i ] + " " ) ; document . write ( " " ) ; } var arr = [ 14 , 6 , 19 , 21 , 12 ] ; var n = arr . length ; pendulumArrangement ( arr , n ) ;
Calculate score of parentheses from a given string | Function to calculate the score of the parentheses using stack ; To keep track of the score ; Initially , push 0 to stack ; Traverse the string s ; If ' ( ' is encountered , then push 0 to stack ; Otherwise ; Balance the last ' ( ' , and store the score of inner parentheses ; If tmp is not zero , it means inner parentheses exists ; Otherwise , it means no inner parentheses exists ; Pass the score of this level to parent parentheses ; Print the score ; Driver Code ; Function call
function scoreOfParentheses ( s ) { var stack = [ ] ; stack . push ( 0 ) ; s . split ( ' ' ) . forEach ( c => { if ( c == ' ' ) stack . push ( 0 ) ; else { var tmp = stack [ stack . length - 1 ] ; stack . pop ( ) ; var val = 0 ; if ( tmp > 0 ) val = tmp * 2 ; else val = 1 ; stack [ stack . length - 1 ] += val ; } } ) ; document . write ( stack [ stack . length - 1 ] ) ; } var S = " " ; scoreOfParentheses ( S ) ;
Count unique substrings of a string S present in a wraparound string | Function to find the count of non - empty substrings of p present in s ; Stores the required answer ; Stores the length of substring present in p ; Stores the current length of substring that is present in string s starting from each character of p ; Iterate over the characters of the string ; Check if the current character can be added with previous substring to form the required substring ; Increment current length ; To avoid repetition ; Update arr [ cur ] ; Print the answer ; Driver code ; Function call to find the count of non - empty substrings of p present in s
function findSubstringInWraproundString ( p ) { let ans = 0 ; let curLen = 0 ; let arr = new Array ( 26 ) ; arr . fill ( 0 ) ; for ( let i = 0 ; i < p . length ; i ++ ) { let curr = p [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; if ( i > 0 && ( p [ i - 1 ] . charCodeAt ( ) != ( ( curr + 26 - 1 ) % 26 + ' ' . charCodeAt ( ) ) ) ) { curLen = 0 ; } curLen ++ ; if ( curLen > arr [ curr ] ) { ans += ( curLen - arr [ curr ] ) ; arr [ curr ] = curLen ; } } document . write ( ans ) ; } let p = " " ; static void Main ( ) { string p = " " ; findSubstringInWraproundString ( p ) ;
Minimize sum of given array by removing all occurrences of a single digit | Function to remove each digit from the given integer ; Convert into string ; Stores final string ; Traverse the string ; Append it to the final string ; Return integer value ; Function to find the minimum sum by removing occurences of each digit ; Iterate in range [ 0 , 9 ] ; Traverse the array ; Update the minimum sum ; Print the minimized sum ; Driver program to test above functions
function remove ( N , digit ) { var strN = N . toString ( ) ; var ans = " " ; var i ; for ( i = 0 ; i < strN . length ; i ++ ) { if ( ( strN . charCodeAt ( i ) - 48 ) == digit ) { continue ; } ans += strN [ i ] ; } return parseInt ( ans ) ; } function getMin ( arr ) { var minSum = 1000000000 ; var i , j ; for ( i = 0 ; i < 10 ; i ++ ) { var curSum = 0 ; for ( j = 0 ; j < arr . length ; j ++ ) { curSum += remove ( arr [ j ] , i ) ; } minSum = Math . min ( minSum , curSum ) ; } document . write ( minSum ) ; } var arr = [ 34 , 23 , 85 , 93 ] ; getMin ( arr ) ;
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 ) ;