codeparrot/xlcost-text-to-code huggingface dataset:
Lexicographical Maximum substring of string | JavaScript program to find the lexicographically maximum substring . ; loop to find the max leicographic substring in the substring array ; Driver code
function LexicographicalMaxString ( str ) { var mx = " " ; for ( var i = 0 ; i < str . length ; ++ i ) { if ( mx . localeCompare ( str . substring ( i ) ) <= 0 ) { mx = str . substring ( i ) ; } } return mx ; } var str = " " ; document . write ( LexicographicalMaxString ( str ) ) ;
Lexicographical Maximum substring of string | Javascript program to find the lexicographically maximum substring . ; We store all the indexes of maximum characters we have in the string ; We form a substring from that maximum character index till end and check if its greater that maxstring ; Driver code
function LexicographicalMaxString ( str ) { let maxchar = ' ' ; let index = [ ] ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] >= maxchar ) { maxchar = str [ i ] ; index . push ( i ) ; } } let maxstring = " " ; for ( let i = 0 ; i < index . length ; i ++ ) { if ( str . substring ( index [ i ] , str . length ) > maxstring ) { maxstring = str . substring ( index [ i ] , str . length ) ; } } return maxstring ; } let str = " " ; document . write ( LexicographicalMaxString ( str ) ) ;
Print longest palindrome word in a sentence | Function to check if a word is palindrome ; making the check case case insensitive ; loop to check palindrome ; Function to find longest palindrome word ; to check last word for palindrome ; to store each word ; extracting each word ; Driver code
function checkPalin ( word ) { let n = word . length ; word = word . toLowerCase ( ) ; for ( let i = 0 ; i < n ; i ++ , n -- ) if ( word [ i ] != word [ n - 1 ] ) return false ; return true ; } function longestPalin ( str ) { str = str + " " ; let longestword = " " , word = " " ; let length , length1 = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { let ch = str [ i ] ; if ( ch != ' ' ) word = word + ch ; else { length = word . length ; if ( checkPalin ( word ) && length > length1 ) { length1 = length ; longestword = word ; } word = " " ; } } return longestword ; } let s = " " + " " ; if ( longestPalin ( s ) == " " ) document . write ( " " + " " ) ; else document . write ( longestPalin ( s ) ) ;
Number of common base strings for two strings | function for finding common divisor ; Checking if ' base ' is base String of ' s1' ; Checking if ' base ' is base String of ' s2' ; Driver code
function isCommonBase ( base , s1 , s2 ) { for ( let j = 0 ; j < s1 . length ; ++ j ) { if ( base [ j % base . length ] != s1 [ j ] ) { return false ; } } for ( let j = 0 ; j < s2 . length ; ++ j ) { if ( base [ j % base . length ] != s2 [ j ] ) { return false ; } } return true ; } function countCommonBases ( s1 , s2 ) { let n1 = s1 . length , n2 = s2 . length ; let count = 0 ; for ( let i = 1 ; i <= Math . min ( n1 , n2 ) ; i ++ ) { let base = s1 . substring ( 0 , i ) ; if ( isCommonBase ( base , s1 , s2 ) ) { count ++ ; } } return count ; } let s1 = " " ; let s2 = " " ; document . write ( countCommonBases ( s1 , s2 ) ) ;
Perfect Square String | JavaScript program to find if string is a perfect square or not . ; Calculating the length of the string ; Calculating the ASCII value of the string ; Find floating point value of square root of x . ; If square root is an integer ; Driver code
function isPerfectSquareString ( str ) { var sum = 0 ; var len = str . length ; for ( var i = 0 ; i < len ; i ++ ) sum += str . charCodeAt ( i ) ; var squareRoot = Math . sqrt ( sum ) ; return squareRoot - Math . floor ( squareRoot ) == 0 ; } var str = " " ; if ( isPerfectSquareString ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;
Count substrings with each character occurring at most k times | function to find number of substring in which each character has count less than or equal to k . ; initialize left and right pointer to 0 ; an array to keep track of count of each alphabet ; decrement the count ; increment left pointer ; Driver code
function find_sub ( s , k ) { let len = s . length ; let lp = 0 , rp = 0 ; let ans = 0 ; let hash_char = new Array ( 26 ) ; for ( let i = 0 ; i < hash_char . length ; i ++ ) { hash_char [ i ] = 0 ; } for ( ; rp < len ; rp ++ ) { hash_char [ s [ rp ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; while ( hash_char [ s [ rp ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] > k ) { hash_char [ s [ lp ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] -- ; lp ++ ; } ans += rp - lp + 1 ; } return ans ; } let S = " " ; let k = 2 ; document . write ( find_sub ( S , k ) ) ;
Find the Number which contain the digit d | Function to display the values ; Converting d to character ; Loop to check each digit one by one . ; Initialize the string ; Checking for digit ; Driver code
function printNumbers ( n , d ) { let st = " " + d ; let ch = st [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { st = " " ; st = st + i ; if ( i == d || st . indexOf ( ch ) >= 0 ) document . write ( i + " " ) ; } } let n = 100 , d = 5 ; printNumbers ( n , d ) ;
Transform a string such that it has abcd . . z as a subsequence | function to transform string with string passed as reference ; initializing the variable ch to ' a ' ; if the length of string is less than 26 , we can 't obtain the required  subsequence ; if ch has reached ' z ' , it means we have transformed our string such that required subsequence can be obtained ; current character is not greater than ch , then replace it with ch and increment ch ; Driver Code
function transformString ( ) { var ch = ' ' ; if ( s . length < 26 ) return false ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( ch . charCodeAt ( 0 ) > 122 ) break ; if ( s [ i ] . charCodeAt ( 0 ) <= ch . charCodeAt ( 0 ) ) { s [ i ] = ch ; ch = String . fromCharCode ( ch . charCodeAt ( 0 ) + 1 ) ; } } s = s . join ( ' ' ) if ( ch . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) return false ; return true ; } var s = " " . split ( ' ' ) ; if ( transformString ( s ) ) document . write ( s ) ; else document . write ( " " ) ;
Number of pairs with Pandigital Concatenation | Checks if a given is Pandigital ; digit i is not present thus not pandigital ; Returns number of pairs of strings resulting in Pandigital Concatenations ; Iterate over all pair of strings ; Driver code
function isPanDigital ( s ) { let digits = new Array ( 10 ) . fill ( false ) ; for ( let i = 0 ; i < s . length ; i ++ ) digits [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] = true ; for ( let i = 0 ; i <= 9 ; i ++ ) if ( digits [ i ] == false ) return false ; return true ; } function countPandigitalPairs ( v ) { let pairs = 0 ; for ( let i = 0 ; i < v . length ; i ++ ) { for ( let j = i + 1 ; j < v . length ; j ++ ) { if ( isPanDigital ( v [ i ] + v [ j ] ) ) { pairs ++ ; } } } return pairs ; } let v = [ " " , " " , " " , " " ] ; document . write ( countPandigitalPairs ( v ) ) ;
Number of pairs with Pandigital Concatenation | Javascript program to count PanDigital pairs ; Stores digits present in string v [ i ] atleast once . We use a set as we only need digits which exist only once ( irrespective of reputation ) ; Calculate the mask by considering all digits existing atleast once ; Increment the frequency of this mask ; Returns number of pairs of strings resulting in Pandigital Concatenations ; All possible strings lie between 1 and 1023 so we iterate over every possible mask ; if the concatenation results in mask of Pandigital Concatenation , calculate all pairs formed with Masks i and j ; Since every pair is considers twice , we get rid of half of these ; Find frequencies of all masks in given vector of strings ; Return all possiblg concatenations . ; Driver code
const pandigitalMask = ( ( 1 << 10 ) - 1 ) ; function computeMaskFrequencies ( v , freq ) { for ( let i = 0 ; i < v . length ; i ++ ) { let mask = 0 ; let digits = new Set ( ) ; for ( let j = 0 ; j < v [ i ] . length ; j ++ ) digits . add ( ( v [ i ] [ j ] ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; for ( let it of digits ) { let digit = it ; mask += ( 1 << digit ) ; } if ( freq . has ( mask ) ) { freq . set ( mask , freq . get ( mask ) + 1 ) } else { freq . set ( mask , 1 ) } } } function pandigitalConcatenations ( freq ) { let ans = 0 ; for ( let i = 1 ; i <= 1023 ; i ++ ) { for ( let j = 1 ; j <= 1023 ; j ++ ) { if ( ( i j ) == pandigitalMask && freq . has ( i ) && freq . has ( j ) ) { if ( i == j ) ans += ( freq . get ( i ) * ( freq . get ( i ) - 1 ) ) ; else ans += ( freq . get ( i ) * freq . get ( j ) ) ; } } } return Math . floor ( ans / 2 ) ; } function countPandigitalPairs ( v ) { let freq = new Map ( ) ; computeMaskFrequencies ( v , freq ) ; return pandigitalConcatenations ( freq ) ; } let v = [ " " , " " , " " , " " ] ; document . write ( countPandigitalPairs ( v ) + " " ) ;
Print the arranged positions of characters to make palindrome | Maximum number of characters ; Insert all positions of every character in the given string . ; find the number of odd elements . Takes O ( n ) ; A palindrome cannot contain more than 1 odd characters ; Print positions in first half of palindrome ; Consider one instance odd character ; Print positions in second half of palindrome ; Driver code
var MAX = 256 ; function printPalindromePos ( str ) { var pos = Array . from ( Array ( MAX ) , ( ) => Array ( ) ) ; var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) pos [ str [ i ] . charCodeAt ( 0 ) ] . push ( i + 1 ) ; var oddCount = 0 ; var oddChar ; for ( var i = 0 ; i < MAX ; i ++ ) { if ( pos [ i ] . length % 2 != 0 ) { oddCount ++ ; oddChar = i ; } } if ( oddCount > 1 ) document . write ( " " ) ; for ( var i = 0 ; i < MAX ; i ++ ) { var mid = pos [ i ] . length / 2 ; for ( var j = 0 ; j < mid ; j ++ ) document . write ( pos [ i ] [ j ] + " " ) ; } if ( oddCount > 0 ) { var last = pos [ oddChar ] . length - 1 ; document . write ( pos [ oddChar ] [ last ] + " " ) ; pos [ oddChar ] . pop ( ) ; } for ( var i = MAX - 1 ; i >= 0 ; i -- ) { var count = pos [ i ] . length ; for ( var j = count / 2 ; j < count ; j ++ ) document . write ( pos [ i ] [ j ] + " " ) ; } } var s = " " ; printPalindromePos ( s ) ;
Minimum changes to a string to make all substrings distinct | javascript program to count number of changes to make all substrings distinct . ; Returns minimum changes to str so that no substring is repeated . ; If length is more than maximum allowed characters , we cannot get the required string . ; Variable to store count of distinct characters ; To store counts of different characters ; Answer is , n - number of distinct char ; Driver function
var MAX_CHAR = 26 ; function minChanges ( str ) { var n = str . length ; if ( n > MAX_CHAR ) return - 1 ; var dist_count = 0 ; var count = Array . from ( { length : MAX_CHAR } , ( _ , i ) => 0 ) ; for ( var i = 0 ; i < MAX_CHAR ; i ++ ) count [ i ] = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( count [ str . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == 0 ) dist_count ++ ; count [ str . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } return ( n - dist_count ) ; } var str = " " ; document . write ( minChanges ( str ) ) ;
Reverse each word in a linked list node | Linked list Node ure ; Function to create newNode in a linked list ; reverse each node data ; iterate each node and call reverse_word for each node data ; printing linked list ; Driver program
class Node { constructor ( ) { this . c = " " ; this . next = null ; } } ; function newNode ( c ) { var temp = new Node ( ) ; temp . c = c ; temp . next = null ; return temp ; } function reverse_word ( str ) { var s = " " ; for ( var i = 0 ; i < str . length ; i ++ ) s = str [ i ] + s ; return s ; } function reverse ( head ) { var ptr = head ; while ( ptr != null ) { ptr . c = reverse_word ( ptr . c ) ; ptr = ptr . next ; } return head ; } function printList ( head ) { while ( head != null ) { document . write ( head . c + " " ) ; head = head . next ; } } var head = newNode ( " " ) ; head . next = newNode ( " " ) ; head . next . next = newNode ( " " ) ; head . next . next . next = newNode ( " " ) ; head . next . next . next . next = newNode ( " " ) ; head . next . next . next . next . next = newNode ( " " ) ; head . next . next . next . next . next . next = newNode ( " " ) ; document . write ( " " ) ; printList ( head ) ; head = reverse ( head ) ; document . write ( " " ) ; printList ( head ) ;
Number of strings of length N with no palindromic sub string | Return the count of strings with no palindromic substring . ; Driver Code
function numofstring ( n , m ) { if ( n == 1 ) return m ; if ( n == 2 ) return m * ( m - 1 ) ; return m * ( m - 1 ) * Math . pow ( m - 2 , n - 2 ) ; } let n = 2 , m = 3 ; document . write ( numofstring ( n , m ) ) ;
Count special palindromes in a String | Function to count special Palindromic susbstring ; store count of special Palindromic substring ; it will store the count of continues same char ; traverse string character from left to right ; store same character count ; count smiler character ; Case : 1 so total number of substring that we can generate are : K * ( K + 1 ) / 2 here K is sameCharCount ; store current same char count in sameChar [ ] array ; increment i ; Case 2 : Count all odd length Special Palindromic substring ; if current character is equal to previous one then we assign Previous same character count to current one ; case 2 : odd length ; subtract all single length substring ; driver program to test above fun
function CountSpecialPalindrome ( str ) { var n = str . length ; var result = 0 ; var sameChar = [ ... Array ( n ) ] ; var i = 0 ; while ( i < n ) { var sameCharCount = 1 ; var j = i + 1 ; while ( str [ i ] == str [ j ] && j < n ) sameCharCount ++ , j ++ ; result += ( sameCharCount * ( sameCharCount + 1 ) ) / 2 ; sameChar [ i ] = sameCharCount ; i = j ; } for ( var j = 1 ; j < n ; j ++ ) { if ( str [ j ] == str [ j - 1 ] ) sameChar [ j ] = sameChar [ j - 1 ] ; if ( j > 0 && j < n - 1 && str [ j - 1 ] == str [ j + 1 ] && str [ j ] != str [ j - 1 ] ) result += Math . min ( sameChar [ j - 1 ] , sameChar [ j + 1 ] ) ; } return result - n ; } var str = " " ; document . write ( CountSpecialPalindrome ( str ) + " " ) ;
Print Bracket Number | function to print the bracket number ; used to print the bracket number for the left bracket ; used to obtain the bracket number for the right bracket ; traverse the given expression ' exp ' ; if current character is a left bracket ; print ' left _ bnum ' , ; push ' left _ bum ' on to the stack ' right _ bnum ' ; increment ' left _ bnum ' by 1 ; else if current character is a right bracket ; print the top element of stack ' right _ bnum ' it will be the right bracket number ; pop the top element from the stack ; Driver program to test above
function printBracketNumber ( exp , n ) { var left_bnum = 1 ; var right_bnum = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( exp [ i ] == ' ' ) { document . write ( left_bnum + " " ) ; right_bnum . push ( left_bnum ) ; left_bnum ++ ; } else if ( exp [ i ] == ' ' ) { document . write ( right_bnum [ right_bnum . length - 1 ] + " " ) ; right_bnum . pop ( ) ; } } } var exp = " " ; var n = exp . length ; printBracketNumber ( exp , n ) ;
Find if a string starts and ends with another given string | JavaScript program to find if a given corner string is present at corners . ; If length of corner string is more , it cannot be present at corners . ; Return true if corner string is present at both corners of given string . ; Driver code
function isCornerPresent ( str , corner ) { var n = str . length ; var cl = corner . length ; if ( n < cl ) return false ; return ( str . substring ( 0 , cl ) . localeCompare ( corner ) === 0 && str . substring ( n - cl , n ) . localeCompare ( corner ) === 0 ) ; } var str = " " ; var corner = " " ; if ( isCornerPresent ( str , corner ) ) document . write ( " " ) ; else document . write ( " " ) ;
Find i 'th Index character in a binary string obtained after n iterations | Javascript Program to find ith character in a binary String . ; Function to store binary Representation ; Function to find ith character ; Function to change decimal to binary ; Assign s1 String in s String ; Driver Code
let s = " " ; function ReverseString ( s ) { let arr = s . split ( " " ) ; for ( let i = 0 ; i < arr . length / 2 ; i ++ ) { let temp = arr [ i ] ; arr [ i ] = arr [ arr . length - i - 1 ] ; arr [ arr . length - i - 1 ] = temp ; } return arr . join ( " " ) ; } function binary_conversion ( m ) { while ( m != 0 ) { let tmp = m % 2 ; s += tmp . toString ( ) ; m = Math . floor ( m / 2 ) ; } s = ReverseString ( s ) ; } function find_character ( n , m , i ) { binary_conversion ( m ) ; let s1 = " " ; for ( let x = 0 ; x < n ; x ++ ) { for ( let y = 0 ; y < s . length ; y ++ ) { if ( s [ y ] == ' ' ) s1 += " " ; else s1 += " " ; } s = s1 ; s1 = " " ; } return s [ i ] - ' ' ; } let m = 5 , n = 2 , i = 8 ; document . write ( find_character ( n , m , i ) ) ;
Consecutive sequenced numbers in a string | function to check consecutive sequential number ; variable to store starting number ; length of the input String ; find the number till half of the String ; new String containing the starting substring of input String ; converting starting substring into number ; backing up the starting number in start ; while loop until the new_String is smaller than input String ; next number ; concatenate the next number ; check if new String becomes equal to input String ; if String doesn 't contains consecutive numbers ; Driver Code
function isConsecutive ( str ) { let start ; let length = str . length ; for ( let i = 0 ; i < length / 2 ; i ++ ) { let new_str = str . substring ( 0 , i + 1 ) ; let num = parseInt ( new_str ) ; start = num ; while ( new_str . length < length ) { num ++ ; new_str = new_str + ( num ) . toString ( ) ; } if ( new_str == ( str ) ) return start ; } return - 1 ; } let str = " " ; document . write ( " " + str + " " ) ; let start = isConsecutive ( str ) ; if ( start != - 1 ) document . write ( " " + start + " " ) ; else document . write ( " " ) ; let str1 = " " ; document . write ( " " + str1 + " " ) ; start = isConsecutive ( str1 ) ; if ( start != - 1 ) document . write ( " " + start + " " ) ; else document . write ( " " ) ;
Converting one string to other using append and delete last operations | Returns true if it is possible to convert str1 to str2 using k operations . ; Case A ( i ) ; finding common length of both string ; Case A ( ii ) - ; Case B - ; driver program
function isConvertible ( str1 , str2 , k ) { if ( ( str1 . length + str2 . length ) < k ) return true ; var commonLength = 0 ; for ( var i = 0 ; i < Math . min ( str1 . length , str2 . length ) ; i ++ ) { if ( str1 [ i ] == str2 [ i ] ) commonLength ++ ; else break ; } if ( ( k - str1 . length - str2 . length + 2 * commonLength ) % 2 == 0 ) return true ; return false ; } var str1 = " " , str2 = " " ; var k = 7 ; if ( isConvertible ( str1 , str2 , k ) ) document . write ( " " ) ; else document . write ( " " ) ; str1 = " " , str2 = " " ; k = 5 ; document . write ( " " ) ; if ( isConvertible ( str1 , str2 , k ) ) document . write ( " " ) ; else document . write ( " " ) ;
Maximum distinct lowercase alphabets between two uppercase | Javascript Program to find maximum lowercase alphabets present between two uppercase alphabets ; Function which computes the maximum number of distinct lowercase alphabets between two uppercase alphabets ; Ignoring lowercase characters in the beginning . ; We start from next of first capital letter and traverse through remaining character . ; If character is in uppercase , ; Count all distinct lower case characters ; Update maximum count ; Reset count array ; If character is in lowercase ; Driver code
let MAX_CHAR = 26 ; function maxLower ( str ) { let n = str . length ; let i = 0 ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' ' && str [ i ] <= ' ' ) { i ++ ; break ; } } let maxCount = 0 ; let count = new Array ( MAX_CHAR ) ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' ' && str [ i ] <= ' ' ) { let currCount = 0 ; for ( let j = 0 ; j < MAX_CHAR ; j ++ ) { if ( count [ j ] > 0 ) { currCount ++ ; } } maxCount = Math . max ( maxCount , currCount ) ; for ( let i = 0 ; i < count . length ; i ++ ) { count [ i ] = 0 ; } } if ( str [ i ] >= ' ' && str [ i ] <= ' ' ) { count [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } } return maxCount ; } let str = " " ; document . write ( maxLower ( str ) ) ;
Maximum distinct lowercase alphabets between two uppercase | Function which computes the maximum number of distinct lowercase alphabets between two uppercase alphabets ; Ignoring lowercase characters in the beginning . ; We start from next of first capital letter and traverse through remaining character . ; If character is in uppercase , ; Update maximum count if lowercase character before this is more . ; clear the set ; If character is in lowercase ; Driver Code
function maxLower ( str ) { let n = str . length ; let i = 0 ; for ( ; i < n ; i ++ ) { if ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) { i ++ ; break ; } } let maxCount = 0 ; let s = new Set ( ) ; for ( ; i < n ; i ++ ) { if ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) { maxCount = Math . max ( maxCount , s . size ) ; s . clear ( ) ; } if ( str [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) s . add ( str [ i ] ) ; } return maxCount ; } let str = " " ; document . write ( maxLower ( str . split ( " " ) ) ) ;
First uppercase letter in a string ( Iterative and Recursive ) | Function to find string which has first character of each word . ; Driver code
function first ( str ) { for ( var i = 0 ; i < str . length ; i ++ ) if ( str [ i ] === str [ i ] . toUpperCase ( ) ) return str [ i ] ; return 0 ; } var str = " " ; var res = first ( str ) ; if ( res == 0 ) document . write ( " " ) ; else { document . write ( res ) ; document . write ( " " ) ; }
Count maximum | factorial of a number ; function to count maximum length palindromes . ; Count number of occurrence of a charterer in the string ; let k = 0 ; Count of singles let num = 0 ; numerator of result let den = 1 ; denominator of result ; if frequency is even fi = ci / 2 ; if frequency is odd fi = ci - 1 / 2. ; sum of all frequencies ; product of factorial of every frequency ; if all character are unique so there will be no pallindrome , so if num != 0 then only we are finding the factorial ; k are the single elements that can be placed in middle ; Driver code
function fact ( n ) { let ans = 1 ; for ( let i = 1 ; i <= n ; i ++ ) ans = ans * i ; return ( ans ) ; } function numberOfPossiblePallindrome ( str , n ) { let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) mp . set ( str [ i ] , mp . get ( str [ i ] ) == null ? 1 : mp . get ( str [ i ] ) + 1 ) ; let fi ; for ( let [ key , value ] of mp . entries ( ) ) { if ( value % 2 == 0 ) fi = value / 2 ; else { fi = ( value - 1 ) / 2 ; k ++ ; } num = num + fi ; den = den * fact ( fi ) ; } if ( num != 0 ) num = fact ( num ) ; let ans = Math . floor ( num / den ) ; if ( k != 0 ) { ans = ans * k ; } return ( ans ) ; } let str = " " ; let n = str . length ; document . write ( numberOfPossiblePallindrome ( str , n ) ) ;
Counting even decimal value substrings in a binary string | generate all substring in arr [ 0. . n - 1 ] ; store the count ; Pick starting point ; Pick ending point ; substring between current starting and ending points ; increment power of 2 by one ; Driver program
function evenDecimalValue ( str , n ) { var result = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i ; j < n ; j ++ ) { var decimalValue = 0 ; var powerOf2 = 1 ; for ( var k = i ; k <= j ; k ++ ) { decimalValue += ( ( str [ k ] - ' ' ) * powerOf2 ) ; powerOf2 *= 2 ; } if ( decimalValue % 2 == 0 ) result ++ ; } } return result ; } var str = " " ; var n = 5 ; document . write ( evenDecimalValue ( str , n ) ) ;