codeparrot/xlcost-text-to-code huggingface dataset:
Count of substrings whose Decimal equivalent is greater than or equal to K | Function to count number of subString whose decimal equivalent is greater than or equal to K ; Left pointer of the subString ; Right pointer of the subString ; Loop to maintain the last occurrence of the 1 in the String ; Variable to count the subString ; Loop to maintain the every possible end index of the subString ; Loop to find the subString whose decimal equivalent is greater than or equal to K ; Condition to check no of bits is out of bound ; Driver Code
function countSubstr ( s , k ) { let n = s . length ; let l = n - 1 ; let r = n - 1 ; let arr = new Array ( n ) ; let last_indexof1 = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) { arr [ i ] = i ; last_indexof1 = i ; } else { arr [ i ] = last_indexof1 ; } } let no_of_substr = 0 ; for ( r = n - 1 ; r >= 0 ; r -- ) { l = r ; while ( l >= 0 && ( r - l + 1 ) <= 64 && parseInt ( s . substring ( l , r + 1 ) , 2 ) < k ) { l -- ; } if ( r - l + 1 <= 64 ) no_of_substr += l + 1 ; else { no_of_substr += arr [ l + 1 ] + 1 ; } } return no_of_substr ; } let s = " " ; let k = 3 ; document . write ( countSubstr ( s , k ) ) ;
Perfect Cube String | JavaScript program to find if string is a perfect cube or not . ; Finding ASCII values of each character and finding its sum ; Find the cube root of sum ; Check if sum is a perfect cube ; Driver code
function isPerfectCubeString ( str ) { var sum = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { sum += str . charCodeAt ( i ) ; } var cr = Math . round ( Math . cbrt ( sum ) ) ; return cr * cr * cr == sum ; } var str = " " ; if ( isPerfectCubeString ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;
Program to find the XOR of ASCII values of characters in a string | Function to find the XOR of ASCII value of characters in string ; store value of first character ; Traverse string to find the XOR ; Return the XOR ; Driver code
function XorAscii ( str , len ) { let ans = str . codePointAt ( 0 ) ; for ( let i = 1 ; i < len ; i ++ ) { ans = ( ans ^ ( str . codePointAt ( i ) ) ) ; } return ans ; } let str = " " ; let len = str . length ; document . write ( XorAscii ( str , len ) + " " ) ; str = " " ; len = str . length ; document . write ( XorAscii ( str , len ) ) ;
Encryption and Decryption of String according to given technique | Function to encrypt the let ; Matrix to generate the Encrypted let ; Fill the matrix row - wise ; Loop to generate encrypted let ; Function to decrypt the let ; Matrix to generate the Encrypted let ; Fill the matrix column - wise ; Loop to generate decrypted let ; Driver Code ; Encryption of let ; Decryption of let
function encryption ( s ) { let l = s . length ; let b = Math . ceil ( Math . sqrt ( l ) ) ; let a = Math . floor ( Math . sqrt ( l ) ) ; let encrypted = ' ' ; if ( b * a < l ) { if ( Math . min ( b , a ) == b ) { b = b + 1 ; } else { a = a + 1 ; } } let arr = new Array ( ) ; for ( let i = 0 ; i < a ; i ++ ) { let temp = [ ] ; for ( let j = 0 ; j < b ; j ++ ) { temp . push ( [ ] ) } arr . push ( temp ) } for ( let i = 0 ; i < a ; i ++ ) { for ( let j = 0 ; j < b ; j ++ ) { arr [ i ] [ j ] = " " } } let k = 0 ; for ( let j = 0 ; j < a ; j ++ ) { for ( let i = 0 ; i < b ; i ++ ) { if ( k < l ) { arr [ j ] [ i ] = s [ k ] ; } k ++ ; } } for ( let j = 0 ; j < b ; j ++ ) { for ( let i = 0 ; i < a ; i ++ ) { encrypted = encrypted + arr [ i ] [ j ] ; } } return encrypted ; } function decryption ( s ) { let l = s . length ; let b = Math . ceil ( Math . sqrt ( l ) ) ; let a = Math . floor ( Math . sqrt ( l ) ) ; let decrypted = ' ' ; let arr = new Array ( ) ; for ( let i = 0 ; i < a ; i ++ ) { let temp = [ ] ; for ( let j = 0 ; j < b ; j ++ ) { temp . push ( [ ] ) } arr . push ( temp ) } for ( let i = 0 ; i < a ; i ++ ) { for ( let j = 0 ; j < b ; j ++ ) { arr [ i ] [ j ] = " " } } let k = 0 ; for ( let j = 0 ; j < b ; j ++ ) { for ( let i = 0 ; i < a ; i ++ ) { if ( k < l ) { arr [ j ] [ i ] = s [ k ] ; } k ++ ; } } for ( let j = 0 ; j < a ; j ++ ) { for ( let i = 0 ; i < b ; i ++ ) { decrypted = decrypted + arr [ i ] [ j ] ; } } return decrypted ; } let s = " " ; let encrypted ; let decrypted ; encrypted = encryption ( s ) ; document . write ( encrypted + " " ) ; decrypted = decryption ( encrypted ) ; document . write ( decrypted ) ;
Program to accept String starting with Capital letter | Function to check if first character is Capital ; Function to check ; Driver function
function checkIfStartsWithCapital ( str ) { if ( str [ 0 ] >= ' ' && str [ 0 ] <= ' ' ) return 1 ; else return 0 ; } function check ( str ) { if ( checkIfStartsWithCapital ( str ) ) document . write ( " " ) ; else document . write ( " " ) ; } var str = " " ; check ( str ) ; str = " " ; check ( str ) ;
Program to accept a Strings which contains all the Vowels | Function to to check that a string contains all vowels ; Hash Array of size 5 such that the index 0 , 1 , 2 , 3 and 4 represent the vowels a , e , i , o and u ; Loop the string to mark the vowels which are present ; Loop to check if there is any vowel which is not present in the string ; Function to to check that a string contains all vowels ; Driver Code
function checkIfAllVowels ( str ) { var hash = Array ( 5 ) . fill ( 0 ) ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' str [ i ] == ' ' ) hash [ 0 ] = 1 ; else if ( str [ i ] == ' ' str [ i ] == ' ' ) hash [ 1 ] = 1 ; else if ( str [ i ] == ' ' str [ i ] == ' ' ) hash [ 2 ] = 1 ; else if ( str [ i ] == ' ' str [ i ] == ' ' ) hash [ 3 ] = 1 ; else if ( str [ i ] == ' ' str [ i ] == ' ' ) hash [ 4 ] = 1 ; } for ( var i = 0 ; i < 5 ; i ++ ) { if ( hash [ i ] == 0 ) { return 1 ; } } return 0 ; } function checkIfAllVowelsArePresent ( str ) { if ( checkIfAllVowels ( str ) ) document . write ( " " ) ; else document . write ( " " ) ; } var str = " " ; checkIfAllVowelsArePresent ( str ) ;
Smallest odd number with even sum of digits from the given number N | Function to find the smallest odd number whose sum of digits is even from the given string ; Converting the given string to a list of digits ; An empty array to store the digits ; For loop to iterate through each digit ; If the given digit is odd then the digit is appended to the array b ; Sorting the list of digits ; If the size of the list is greater than 1 then a 2 digit smallest odd number is returned . Since the sum of two odd digits is always even ; Else , - 1 is returned ; Driver code
function smallest ( s ) { var a = Array ( s . length ) ; for ( var i = 0 ; i < s . length ; i ++ ) a [ i ] = s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; var b = [ ] ; for ( var i = 0 ; i < a . length ; i ++ ) { if ( ( a [ i ] ) % 2 != 0 ) b . push ( a [ i ] ) ; } b . sort ( ( a , b ) => a - b ) ; if ( b . length > 1 ) return ( b [ 0 ] ) * 10 + ( b [ 1 ] ) ; return - 1 ; } document . write ( smallest ( " " ) ) ;
Number formed by deleting digits such that sum of the digits becomes even and the number odd | Function to convert a number into odd number such that digit - sum is odd ; Loop to find any first two odd number such that their sum is even and number is odd ; Print the result ; Driver Code
function converthenumber ( n ) { var s = n . toString ( ) ; var res = " " ; var i ; for ( i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) res += s [ i ] ; if ( res . length == 2 ) break ; } if ( res . length == 2 ) document . write ( res ) ; else document . write ( " " ) ; } var n = 18720 ; converthenumber ( n ) ;
Longest palindromic String formed using concatenation of given strings in any order | Function to find the longest palindromic from given array of strings ; Loop to find the pair of strings which are reverse of each other ; Loop to find if any palindromic string is still left in the array ; Update the answer with all strings of pair1 ; Update the answer with palindromic string s1 ; Update the answer with all strings of pair2 ; Driver Code
function longestPalindrome ( a , n ) { var pair1 = Array ( n ) ; var pair2 = Array ( n ) ; var r = 0 ; for ( var i = 0 ; i < n ; i ++ ) { var s = a [ i ] ; s = s . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; for ( var j = i + 1 ; j < n ; j ++ ) { if ( a [ i ] != " " && a [ j ] != " " ) { if ( s == a [ j ] ) { pair1 [ r ] = a [ i ] ; pair2 [ r ++ ] = a [ j ] ; a [ i ] = " " ; a [ j ] = " " ; break ; } } } } var s1 = " " ; for ( var i = 0 ; i < n ; i ++ ) { var s = a [ i ] ; a [ i ] = a [ i ] . split ( ' ' ) . reverse ( ) . join ( ' ' ) ; if ( a [ i ] != " " ) { if ( a [ i ] == s ) { s1 = a [ i ] ; break ; } } } var ans = " " ; for ( var i = 0 ; i < r ; i ++ ) { ans = ans + pair1 [ i ] ; } if ( s1 != " " ) { ans = ans + s1 ; } for ( var j = r - 1 ; j >= 0 ; j -- ) { ans = ans + pair2 [ j ] ; } document . write ( ans + " " ) ; } var a1 = [ " " , " " ] ; var n1 = a1 . length ; longestPalindrome ( a1 , n1 ) ; var a2 = [ " " , " " , " " , " " , " " ] ; var n2 = a2 . length ; longestPalindrome ( a2 , n2 ) ;
Program to print the given digit in words | Function to return the word of the corresponding digit ; Switch block to check for each digit c ; For digit 0 ; For digit 1 ; For digit 2 ; For digit 3 ; For digit 4 ; For digit 5 ; For digit 6 ; For digit 7 ; For digit 8 ; For digit 9 ; Function to iterate through every digit in the given number ; Finding each digit of the number ; Print the digit in words ; Driver code
function printValue ( digit ) { switch ( digit ) { case " " : document . write ( " " ) ; break ; case " " : document . write ( " " ) ; break ; case " " : document . write ( " " ) ; break ; case " " : document . write ( " " ) ; break ; case " " : document . write ( " " ) ; break ; case " " : document . write ( " " ) ; break ; case " " : document . write ( " " ) ; break ; case " " : document . write ( " " ) ; break ; case " " : document . write ( " " ) ; break ; case " " : document . write ( " " ) ; break ; } } function printWord ( N ) { var i , length = N . length ; for ( i = 0 ; i < length ; i ++ ) { printValue ( N [ i ] ) ; } } var N = " " ; printWord ( N ) ;
Sum of all LCP of maximum length by selecting any two Strings at a time | Javascript program to find Sum of all LCP of maximum length by selecting any two Strings at a time ; Initially visited value for all nodes is zero ; Counts the number of times the node is visited while making the trie ; Using map to store the pointers of children nodes for dynamic implementation , for making the program space efiicient ; Head node of the trie is initialize as ' \0' , after this all Strings add ; Function to insert the Strings in the trie ; Inserting character - by - character ; If the node of ch is not present in map make a new node and add in map ; Recursive function to calculate the answer argument is passed by reference ; To store changed visited values from children of this node i . e . number of nodes visited by its children ; Updating the visited variable , telling number of nodes that have already been visited by its children ; If node . visited > 1 , means more than one String has prefix up till this node common in them ; Number of String pair with current node common in them ; Updating visited variable of current node ; Returning the total number of nodes already visited that needs to be updated to previous node ; Function to run the dfs function for the first time and give the answer variable ; Stores the final answer as sum of all depths ; Driver code
class TrieNode { constructor ( x ) { this . val = x ; this . visited = 0 ; this . children = new Map ( ) ; } } class Trie { constructor ( ) { this . head = new TrieNode ( ' \0 ' ) ; this . ans = 0 ; } addWord ( s ) { let temp = this . head ; let n = s . length ; for ( let i = 0 ; i < n ; i ++ ) { let ch = s [ i ] ; if ( temp . children . get ( ch ) == null ) { temp . children . set ( ch , new TrieNode ( ch ) ) ; } temp = temp . children . get ( ch ) ; temp . visited ++ ; } } dfs ( node , depth ) { let vis = 0 ; for ( let [ key , value ] of node . children . entries ( ) ) { vis += this . dfs ( value , depth + 1 ) ; } node . visited -= vis ; let String_pair = 0 ; if ( node . visited > 1 ) { String_pair = ( node . visited / 2 ) ; this . ans += ( depth * String_pair ) ; node . visited -= ( 2 * String_pair ) ; } return ( 2 * String_pair + vis ) ; } dfshelper ( ) { this . ans = 0 ; this . dfs ( this . head , 0 ) ; return this . ans ; } } let T = new Trie ( ) ; let str = [ " " , " " , " " , " " , " " , " " ] ; let n = 6 ; for ( let i = 0 ; i < n ; i ++ ) { T . addWord ( str [ i ] ) ; } let ans = T . dfshelper ( ) ; document . write ( ans ) ;
Jaro and Jaro | Function to calculate the Jaro Similarity of two strings ; If the strings are equal ; Length of two strings ; Maximum distance upto which matching is allowed ; Count of matches ; Hash for matches ; Traverse through the first string ; Check if there is any matches ; If there is a match ; If there is no match ; Number of transpositions ; Count number of occurrences where two characters match but there is a third matched character in between the indices ; Find the next matched character in second string ; Return the Jaro Similarity ; Driver code ; Print jaro Similarity of two strings
function jaro_distance ( s1 , s2 ) { if ( s1 == s2 ) return 1.0 ; var len1 = s1 . length , len2 = s2 . length ; var max_dist = Math . floor ( Math . max ( len1 , len2 ) / 2 ) - 1 ; var match = 0 ; var hash_s1 = Array ( s1 . length ) . fill ( 0 ) ; var hash_s2 = Array ( s1 . length ) . fill ( 0 ) ; for ( var i = 0 ; i < len1 ; i ++ ) { for ( var j = Math . max ( 0 , i - max_dist ) ; j < Math . min ( len2 , i + max_dist + 1 ) ; j ++ ) if ( s1 [ i ] == s2 [ j ] && hash_s2 [ j ] == 0 ) { hash_s1 [ i ] = 1 ; hash_s2 [ j ] = 1 ; match ++ ; break ; } } if ( match == 0 ) return 0.0 ; var t = 0 ; var point = 0 ; for ( var i = 0 ; i < len1 ; i ++ ) if ( hash_s1 [ i ] ) { while ( hash_s2 [ point ] == 0 ) point ++ ; if ( s1 [ i ] != s2 [ point ++ ] ) t ++ ; } t /= 2 ; return ( ( match ) / ( len1 ) + ( match ) / ( len2 ) + ( match - t ) / ( match ) ) / 3.0 ; } var s1 = " " , s2 = " " ; document . write ( jaro_distance ( s1 , s2 ) . toFixed ( 5 ) ) ;
Print characters and their frequencies in order of occurrence using Binary Tree | Node in the tree where data holds the character of the String and cnt holds the frequency ; Function to add a new node to the Binary Tree ; Create a new node and populate its data part , set cnt as 1 and left and right children as null ; Function to add a node to the Binary Tree in level order ; Use the queue data structure for level order insertion and push the root of tree to Queue ; If the character to be inserted is present , update the cnt ; If the left child is empty add a new node as the left child ; If the character is present as a left child , update the cnt and exit the loop ; push the left child to the queue for further processing ; If the right child is empty , add a new node to the right ; If the character is present as a right child , update the cnt and exit the loop ; push the right child to the queue for further processing ; Function to print the level order traversal of the Binary Tree ; push the root to the queue ; If the cnt of the character is more then one , display cnt ; If the cnt of character is one , display character only ; push the left child to the queue for further processing ; push the right child to the queue for further processing ; Driver code ; push individual characters to the String one by one in level order ; Print the level order of the constructed binary tree
class node { constructor ( ) { this . data = ' ' ; this . cnt = 0 ; this . left = null ; this . right = null ; } } ; function add ( data ) { var newnode = new node ( ) ; newnode . data = data ; newnode . cnt = 1 ; newnode . left = newnode . right = null ; return newnode ; } function addinlvlorder ( root , data ) { if ( root == null ) { return add ( data ) ; } var Q = [ ] ; Q . push ( root ) ; while ( Q . length != 0 ) { var temp = Q [ 0 ] ; Q . shift ( ) ; if ( temp . data == data ) { temp . cnt ++ ; break ; } if ( temp . left == null ) { temp . left = add ( data ) ; break ; } else { if ( temp . left . data == data ) { temp . left . cnt ++ ; break ; } Q . push ( temp . left ) ; } if ( temp . right == null ) { temp . right = add ( data ) ; break ; } else { if ( temp . right . data == data ) { temp . right . cnt ++ ; break ; } Q . push ( temp . right ) ; } } return root ; } function printlvlorder ( root ) { var Q = [ ] ; Q . push ( root ) ; while ( Q . length != 0 ) { var temp = Q [ 0 ] ; if ( temp . cnt > 1 ) { document . write ( ( temp . data + " " + temp . cnt ) ) ; } else { document . write ( temp . data ) ; } Q . shift ( ) ; if ( temp . left != null ) { Q . push ( temp . left ) ; } if ( temp . right != null ) { Q . push ( temp . right ) ; } } } var s = " " ; var root = null ; for ( var i = 0 ; i < s . length ; i ++ ) { root = addinlvlorder ( root , s [ i ] ) ; } printlvlorder ( root ) ;
Check if all bits can be made same by flipping two consecutive bits | Function to check if Binary string can be made equal ; Counting occurence of zero and one in binary string ; From above observation ; Driver code
function canMake ( s ) { var o = 0 , z = 0 ; for ( i = 0 ; i < s . length ; i ++ ) { if ( s . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) == 1 ) o ++ ; else z ++ ; } if ( o % 2 == 1 && z % 2 == 1 ) return " " ; else return " " ; } var s = " " ; document . write ( canMake ( s ) ) ;
Count of non | Javascript implementation of the above approach ; Function to find the count of the number of strings ; Loop to iterate over the frequency of character of string ; reduce the frequency of current element ; recursive call ; freq [ i ] ++ ; backtrack ; Function to count the number of non - empty sequences ; store the frequency of each character ; Maintain the frequency ; Driver Code ; Function Call
let count = 0 ; function countNumberOfStringsUtil ( freq ) { for ( let i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] > 0 ) { freq [ i ] -- ; count ++ ; countNumberOfStringsUtil ( freq ) ; } } } function countNumberOfStrings ( s ) { let freq = new Array ( 26 ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < s . length ; i ++ ) { freq [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } countNumberOfStringsUtil ( freq ) ; return count ; } let s = " " ; document . write ( countNumberOfStrings ( s ) ) ;
Minimum swaps required to make a binary string divisible by 2 ^ k | Function to return the minimum swaps required ; To store the final answer ; To store the count of one and zero ; Loop from end of the string ; If s [ i ] = 1 ; If s [ i ] = 0 ; If c_zero = k ; If the result can 't  be achieved ; Return the final answer ; Driver code
function findMinSwaps ( s , k ) { var ans = 0 ; var c_one = 0 , c_zero = 0 ; for ( var i = s . length - 1 ; i >= 0 ; i -- ) { if ( s [ i ] == ' ' ) c_one ++ ; if ( s [ i ] == ' ' ) c_zero ++ , ans += c_one ; if ( c_zero == k ) break ; } if ( c_zero < k ) return - 1 ; return ans ; } var s = " " ; var k = 2 ; document . write ( findMinSwaps ( s , k ) ) ;
Remove vowels from a string stored in a Binary Tree | Structure Representing the Node in the Binary tree ; Function to perform a level order insertion of a new Node in the Binary tree ; If the root is empty , make it point to the new Node ; In case there are elements in the Binary tree , perform a level order traversal using a Queue ; If the left child does not exist , insert the new Node as the left child ; In case the right child does not exist , insert the new Node as the right child ; Function to print the level order traversal of the Binary tree ; Function to check if the character is a vowel or not . ; Function to remove the vowels in the new Binary tree ; Declaring the root of the new tree ; If the given character is not a vowel , push it to the new Binary tree ; Driver code
class Node { constructor ( _val ) { this . data = _val ; this . left = null ; this . right = null ; } } ; function addinBT ( root , data ) { if ( root == null ) { root = new Node ( data ) ; } else { var Q = [ ] ; Q . push ( root ) ; while ( Q . length != 0 ) { var temp = Q [ 0 ] ; Q . shift ( ) ; if ( temp . left == null ) { temp . left = new Node ( data ) ; break ; } else Q . push ( temp . left ) ; if ( temp . right == null ) { temp . right = new Node ( data ) ; break ; } else Q . push ( temp . right ) ; } } return root ; } function print ( root ) { var Q = [ ] Q . push ( root ) ; while ( Q . length > 0 ) { var temp = Q [ 0 ] ; Q . shift ( ) ; document . write ( temp . data ) ; if ( temp . left != null ) Q . push ( temp . left ) ; if ( temp . right != null ) Q . push ( temp . right ) ; } } function checkvowel ( ch ) { ch = ch . toLowerCase ( ) ; if ( ch == " " ch == " " ch == " " ch == " " ch == " " ) { return true ; } else { return false ; } } function removevowels ( root ) { var Q = [ ] Q . push ( root ) ; var root1 = null ; while ( Q . length != 0 ) { var temp = Q [ 0 ] ; Q . shift ( ) ; if ( ! checkvowel ( temp . data ) ) { root1 = addinBT ( root1 , temp . data ) ; } if ( temp . left != null ) { Q . push ( temp . left ) ; } if ( temp . right != null ) { Q . push ( temp . right ) ; } } return root1 ; } var s = " " ; var root = null ; for ( var i = 0 ; i < s . length ; i ++ ) { root = addinBT ( root , s [ i ] ) ; } root = removevowels ( root ) ; print ( root ) ;
Number of sub | Function to return the count of the required substrings ; To store the final answer ; Loop to find the answer ; Condition to update the answer ; Driver code
function countSubStr ( str , len ) { var ans = 0 ; for ( var i = 0 ; i < len ; i ++ ) { if ( str [ i ] == ' ' ) ans += ( i + 1 ) ; } return ans ; } var str = " " ; var len = str . length ; document . write ( countSubStr ( str , len ) ) ;
Smallest non | Function to return the length of the smallest substring divisible by 2 ^ k ; To store the final answer ; Left pointer ; Right pointer ; Count of the number of zeros and ones in the current substring ; Loop for two pointers ; Condition satisfied ; Updated the answer ; Update the pointer and count ; Update the pointer and count ; Driver code
function findLength ( s , k ) { var ans = 1000000000 ; var l = 0 ; var r = 0 ; var cnt_zero = 0 , cnt_one = 0 ; while ( l < s . length && r <= s . length ) { if ( cnt_zero >= k && cnt_one >= 1 ) { ans = Math . min ( ans , r - l ) ; l ++ ; if ( s [ l - 1 ] == ' ' ) cnt_zero -- ; else cnt_one -- ; } else { if ( r == s . length ) break ; if ( s [ r ] == ' ' ) cnt_zero ++ ; else cnt_one ++ ; r ++ ; } } if ( ans == 1000000000 ) return - 1 ; return ans ; } var s = " " ; var k = 2 ; document . write ( findLength ( s , k ) ) ;
Largest sub | Function to return the largest substring divisible by 2 ; While the last character of the string is '1' , pop it ; If the original string had no '0' ; Driver code
function largestSubStr ( s ) { while ( s . length && s [ s . length - 1 ] == ' ' ) s = s . substring ( 0 , s . length - 1 ) ; ; if ( s . length == 0 ) return " " ; else return s ; } var s = " " ; document . write ( largestSubStr ( s ) ) ;