codeparrot/xlcost-text-to-code huggingface dataset:
Find the number obtained after concatenation of binary representation of M and N | Function to convert decimal number n to its binary representation stored as an array [ ] arr ; Funtion to convert the number represented as a binary array [ ] arr into its decimal equivalent ; Function to concatenate the binary numbers and return the decimal result ; Number of bits in both the numbers ; Convert the bits in both the integers to the arrays [ ] a and [ ] b ; c [ ] will be the binary array for the result ; Update the c [ ] array ; Return the decimal equivalent of the result ; Driver code
function decBinary ( arr , n ) { let k = parseInt ( Math . log ( n ) / Math . log ( 2 ) , 10 ) ; while ( n > 0 ) { arr [ k -- ] = n % 2 ; n = parseInt ( n / 2 , 10 ) ; } } function binaryDec ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) ans += arr [ i ] << ( n - i - 1 ) ; return ans ; } function concat ( m , n ) { let k = parseInt ( Math . log ( m ) / Math . log ( 2 ) , 10 ) + 1 ; let l = parseInt ( Math . log ( n ) / Math . log ( 2 ) , 10 ) + 1 ; let a = new Array ( k ) ; let b = new Array ( l ) ; let c = new Array ( k + l ) ; decBinary ( a , m ) ; decBinary ( b , n ) ; let iN = 0 ; for ( let i = 0 ; i < k ; i ++ ) c [ iN ++ ] = a [ i ] ; for ( let i = 0 ; i < l ; i ++ ) c [ iN ++ ] = b [ i ] ; return ( binaryDec ( c , k + l ) ) ; } let m = 4 , n = 5 ; document . write ( concat ( m , n ) ) ;
Find the number obtained after concatenation of binary representation of M and N | Utility function to calculate binary length of a number . ; Function to concatenate the binary numbers and return the decimal result ; Find binary length of n ; left binary shift m and then add n ; Driver code
function getBinaryLength ( n ) { let length = 0 ; while ( n > 0 ) { length += 1 ; n = parseInt ( n / 2 , 10 ) ; } return length ; } function concat ( m , n ) { let length = getBinaryLength ( n ) ; return ( m << length ) + n ; } let m = 4 , n = 5 ; document . write ( concat ( m , n ) ) ;
XOR two binary strings of unequal lengths | Function to insert n 0 s in the beginning of the given string ; Function to return the XOR of the given strings ; Lengths of the given strings ; Make both the strings of equal lengths by inserting 0 s in the beginning ; Updated length ; To store the resultant XOR ; Driver code
function addZeros ( str , n ) { for ( let i = 0 ; i < n ; i ++ ) { str = " " + str ; } return str ; } function getXOR ( a , b ) { let aLen = a . length ; let bLen = b . length ; if ( aLen > bLen ) { a = addZeros ( b , aLen - bLen ) ; } else if ( bLen > aLen ) { a = addZeros ( a , bLen - aLen ) ; } let len = Math . max ( aLen , bLen ) ; let res = " " ; for ( let i = 0 ; i < len ; i ++ ) { if ( a [ i ] == b [ i ] ) res += " " ; else res += " " ; } return res ; } let a = " " , b = " " ; document . write ( getXOR ( a , b ) ) ;
Minimum operations required to make the string satisfy the given condition | Javascript implementation of the approach ; Function to return the minimum operations required ; To store the first and the last occurrence of all the characters ; Update the occurrences of the characters ; Only set the first occurrence if it hasn 't already been set ; To store the minimum operations ; If the frequency of the current character in the string is less than 2 ; Count of characters to be removed so that the string starts and ends at the current character ; Driver code
var MAX = 26 ; function minOperation ( str , len ) { var first = Array ( MAX ) . fill ( - 1 ) ; var last = Array ( MAX ) . fill ( - 1 ) ; for ( var i = 0 ; i < len ; i ++ ) { var index = ( str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; if ( first [ index ] == - 1 ) first [ index ] = i ; last [ index ] = i ; } var minOp = - 1 ; for ( var i = 0 ; i < MAX ; i ++ ) { if ( first [ i ] == - 1 first [ i ] == last [ i ] ) continue ; var cnt = len - ( last [ i ] - first [ i ] + 1 ) ; if ( minOp == - 1 cnt < minOp ) minOp = cnt ; } return minOp ; } var str = " " ; var len = str . length ; document . write ( minOperation ( str , len ) ) ;
Queries to find the count of vowels in the substrings of the given string | Javascript implementation of the approach ; Function that returns true if ch is a vowel ; Function to return the count of vowels in the substring str [ l ... r ] ; To store the count of vowels ; For every character in the index range [ l , r ] ; If the current character is a vowel ; For every query ; Find the count of vowels for the current query ; Driver code
let N = 2 ; function isVowel ( ch ) { return ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) ; } function countVowels ( str , l , r ) { let cnt = 0 ; for ( let i = l ; i <= r ; i ++ ) { if ( isVowel ( str [ i ] ) ) cnt ++ ; } return cnt ; } function performQueries ( str , queries , q ) { for ( let i = 0 ; i < q ; i ++ ) { document . write ( countVowels ( str , queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) + " " ) ; } } let str = " " ; let queries = [ [ 1 , 3 ] , [ 2 , 4 ] , [ 1 , 9 ] ] ; let q = queries . length ; performQueries ( str , queries , q ) ;
Convert a String to a Singly Linked List | Structure for a Singly Linked List ; Function to add a new node to the Linked List ; Function to convert the string to Linked List . ; curr pointer points to the current node where the insertion should take place ; Function to print the data present in all the nodes ; Driver code
class node { constructor ( ) { this . data = ' ' ; this . next = null ; } } function add ( data ) { let newnode = new node ( ) ; newnode . data = data ; newnode . next = null ; return newnode ; } function string_to_SLL ( text , head ) { head = add ( text [ 0 ] ) ; let curr = head ; for ( let i = 1 ; i < text . length ; i ++ ) { curr . next = add ( text [ i ] ) ; curr = curr . next ; } return head ; } function print ( head ) { let curr = head ; while ( curr != null ) { document . write ( curr . data + " " ) ; curr = curr . next ; } } let text = " " ; let head = null ; head = string_to_SLL ( text , head ) ; print ( head ) ;
Reduce the string to minimum length with the given operation | Function to return the minimum possible length str can be reduced to with the given operation ; Stack to store the characters of the given string ; For every character of the string ; If the stack is empty then push the current character in the stack ; Get the top character ; If the top element is not equal to the current element and it only differs in the case ; Pop the top element from stack ; Else push the current element ;
function minLength ( str , len ) { let s = [ ] ; for ( let i = 0 ; i < len ; i ++ ) { if ( s . length == 0 ) { s . push ( str [ i ] ) ; } else { let c = s [ s . length - 1 ] ; if ( c != str [ i ] && c . toUpperCase ( ) == str [ i ] . toUpperCase ( ) ) { s . pop ( ) ; } else { s . push ( str [ i ] ) ; } } } return s . length ; } ' ' ' ' ' ' let str = " " ; let len = str . length ; document . write ( minLength ( str , len ) ) ;
Check whether two strings can be made equal by copying their characters with the adjacent ones | JavaScript implementation of the above approach ; Function that returns true if both the strings can be made equal with the given operation ; Lengths of both the strings have to be equal ; To store the frequency of the characters of str1 ; For every character of str2 ; If current character of str2 also appears in str1 ; Driver code
let MAX = 26 ; function canBeMadeEqual ( str1 , str2 ) { let len1 = str1 . length ; let len2 = str2 . length ; if ( len1 == len2 ) { let freq = new Array ( MAX ) ; freq . fill ( 0 ) ; for ( let i = 0 ; i < len1 ; i ++ ) { freq [ str1 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; } for ( let i = 0 ; i < len2 ; i ++ ) { if ( freq [ str2 [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] > 0 ) return true ; } } return false ; } let str1 = " " , str2 = " " ; if ( canBeMadeEqual ( str1 , str2 ) ) document . write ( " " ) ; else document . write ( " " ) ;
Minimum characters that are to be inserted such that no three consecutive characters are same | Function to return the count of characters that are to be inserted in str such that no three consecutive characters are same ; To store the count of operations required ; A character needs to be inserted after str [ i + 1 ] ; Current three consecutive characters are not same ; Driver code
function getCount ( str , n ) { var cnt = 0 ; var i = 0 ; while ( i < n - 2 ) { if ( str [ i ] === str [ i + 1 ] && str [ i ] === str [ i + 2 ] ) { cnt ++ ; i = i + 2 ; } else { i ++ ; } } return cnt ; } var str = " " ; var n = str . length ; document . write ( getCount ( str , n ) ) ;
Find the number of strings formed using distinct characters of a given string | Function to return the factorial of n ; Function to return the count of all possible strings that can be formed with the characters of the given string without repeating characters ; To store the distinct characters of the string str ; Driver code
function fact ( n ) { let fact = 1 ; for ( let i = 1 ; i <= n ; i ++ ) fact *= i ; return fact ; } function countStrings ( str , n ) { let distinct_char = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) { distinct_char . add ( str [ i ] ) ; } return fact ( distinct_char . size ) ; } let str = " " ; let n = str . length ; document . write ( countStrings ( str , n ) ) ;
Find the character made by adding all the characters of the given string | Function to return the required character ; To store the sum of the characters of the given string ; Add the current character to the sum ; Return the required character ; Driver code
function getChar ( str ) { let sum = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) { sum += ( str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) + 1 ) ; } if ( sum % 26 == 0 ) return ' ' ; else { sum = sum % 26 ; return String . fromCharCode ( ' ' . charCodeAt ( ) + sum - 1 ) ; } } let str = " " ; document . write ( getChar ( str ) ) ;
Reverse the given string in the range [ L , R ] | Function to return the string after reversing characters in the range [ L , R ] ; Invalid range ; While there are characters to swap ; Swap ( str [ l ] , str [ r ] ) ; Driver code
function reverse ( str , len , l , r ) { if ( l < 0 r >= len l > r ) return " " ; while ( l < r ) { let c = str [ l ] ; str [ l ] = str [ r ] ; str [ r ] = c ; l ++ ; r -- ; } return str . join ( " " ) ; } let str = " " ; let len = str . length ; let l = 5 , r = 7 ; document . write ( reverse ( str . split ( ' ' ) , len , l , r ) ) ;
Program to Encrypt a String using ! and @ | Function to encrypt the string ; evenPos is for storing encrypting char at evenPosition oddPos is for storing encrypting char at oddPosition ; Get the number of times the character is to be repeated ; if i is odd , print ' ! ' else print ' @ ' ; Driver code ; Encrypt the String
function encrypt ( input ) { let evenPos = ' ' , oddPos = ' ' ; let repeat , ascii ; for ( let i = 0 ; i < input . length ; i ++ ) { ascii = input [ i ] . charCodeAt ( ) ; repeat = ascii >= 97 ? ascii - 96 : ascii - 64 ; for ( let j = 0 ; j < repeat ; j ++ ) { if ( i % 2 == 0 ) document . write ( oddPos ) ; else document . write ( evenPos ) ; } } } let input = [ ' ' , ' ' , ' ' , ' ' ] ; encrypt ( input ) ;
Check if expression contains redundant bracket or not | Set 2 | Function to check for redundant braces ; count of no of signs ; Driver Code
function IsRedundantBraces ( A ) { let a = 0 , b = 0 ; for ( let i = 0 ; i < A . length ; i ++ ) { if ( A [ i ] == ' ' && A [ i + 2 ] == ' ' ) return true ; if ( A [ i ] == ' ' A [ i ] == ' ' A [ i ] == ' ' A [ i ] == ' ' ) a ++ ; if ( A [ i ] == ' ' ) b ++ ; } if ( b > a ) return true ; return false ; } let A = " " ; if ( IsRedundantBraces ( A ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Convert an unbalanced bracket sequence to a balanced sequence | Function to return balancedBrackets string ; Initializing dep to 0 ; Stores maximum negative depth ; if dep is less than minDep ; if minDep is less than 0 then there is need to add ' ( ' at the front ; Reinitializing to check the updated string ; if dep is not 0 then there is need to add ' ) ' at the back ; Driver code
function balancedBrackets ( str ) { var dep = 0 ; var minDep = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] === " " ) dep ++ ; else dep -- ; if ( minDep > dep ) minDep = dep ; } if ( minDep < 0 ) { for ( var i = 0 ; i < Math . abs ( minDep ) ; i ++ ) str = " " + str ; } dep = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] === " " ) dep ++ ; else dep -- ; } if ( dep !== 0 ) { for ( var i = 0 ; i < dep ; i ++ ) str = str + " " ; } return str ; } var str = " " ; document . write ( balancedBrackets ( str ) ) ;
Minimum operations required to convert a binary string to all 0 s or all 1 s | Function to return the count of minimum operations required ; Increment count when consecutive characters are different ; Answer is rounding off the ( count / 2 ) to lower ; Driver code
function minOperations ( str , n ) { var count = 0 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { if ( str [ i ] != str [ i + 1 ] ) count ++ ; } return ( count + 1 ) / 2 ; } var str = " " ; var n = str . length ; document . write ( minOperations ( str , n ) ) ;
Append a digit in the end to make the number equal to the length of the remaining string | Function to return the required digit ; To store the position of the first numeric digit in the string ; To store the length of the string without the numeric digits in the end ; pw stores the current power of 10 and num is to store the number which is appended in the end ; If current character is a numeric digit ; Get the current digit ; Build the number ; If number exceeds the length ; Next power of 10 ; Append 0 in the end ; Required number that must be added ; If number is not a single digit ; Driver code
function find_digit ( s , n ) { var first_digit = - 1 ; for ( var i = n - 1 ; i >= 0 ; i -- ) { if ( s [ i ] < ' ' s [ i ] > ' ' ) { first_digit = i ; break ; } } first_digit ++ ; var s_len = first_digit ; var num = 0 , pw = 1 ; var i = n - 1 ; while ( i >= 0 ) { if ( s [ i ] >= ' ' && s [ i ] <= ' ' ) { var digit = s [ i ] - ' ' ; num = num + ( pw * digit ) ; if ( num >= s_len ) return - 1 ; pw = pw * 10 ; } i -- ; } num = num * 10 ; var req = s_len - num ; if ( req > 9 req < 0 ) return - 1 ; return req ; } var s = " " ; var n = s . length ; document . write ( find_digit ( s , n ) ) ;
Check whether str1 can be converted to str2 with the given operations | Function that returns true if str1 can be converted to str2 with the given operations ; Traverse from left to right ; If the two characters do not match ; If possible to combine ; If not possible to combine ; If the two characters match ; If possible to convert one string to another ; Driver code
function canConvert ( str1 , str2 ) { var i = 0 , j = 0 ; while ( i < str1 . length && j < str2 . length ) { if ( str1 [ i ] !== str2 [ j ] ) { if ( str1 [ i ] === " " && str2 [ j ] === " " && i + 1 < str1 . length && str1 [ i + 1 ] === " " ) { i += 2 ; j ++ ; } else { return false ; } } else { i ++ ; j ++ ; } } if ( i === str1 . length && j === str2 . length ) return true ; return false ; } var str1 = " " , str2 = " " ; if ( canConvert ( str1 , str2 ) ) document . write ( " " ) ; else document . write ( " " ) ;
Reverse the Words of a String using Stack | Function to reverse the words of the given String without using strtok ( ) . ; Create an empty String stack ; Create an empty temporary String ; Traversing the entire String ; Push the temporary variable into the stack ; Assigning temporary variable as empty ; For the last word of the String ; Get the words in reverse order ; Driver code
function reverse ( s ) { let stc = [ ] ; let temp = " " ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) { stc . push ( temp ) ; temp = " " ; } else { temp = temp + s [ i ] ; } } stc . push ( temp ) ; while ( stc . length != 0 ) { temp = stc [ stc . length - 1 ] ; document . write ( temp + " " ) ; stc . pop ( ) ; } } let s = " " ; reverse ( s ) ;
Print an N x M matrix such that each row and column has all the vowels in it | Function to print the required matrix ; Impossible to generate the required matrix ; Store all the vowels ; Print the matrix ; Print vowels for every index ; Shift the vowels by one ; Driver code
function printMatrix ( n , m ) { if ( n < 5 m < 5 ) { document . write ( - 1 ) ; return ; } var s = " " ; for ( var i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { document . write ( s [ j % 5 ] + " " ) ; } document . write ( " " ) ; var c = s [ 0 ] ; s = s . substring ( 1 , s . length ) + s . substring ( 0 , 1 ) ; s [ 4 ] = c ; } } var n = 5 , m = 5 ; printMatrix ( n , m ) ;
Check if a given string is made up of two alternating characters | Function that returns true if the string is made up of two alternating characters ; Check if ith character matches with the character at index ( i + 2 ) ; If string consists of a single character repeating itself ; Driver code
function isTwoAlter ( s ) { for ( let i = 0 ; i < s . length - 2 ; i ++ ) { if ( s [ i ] != s [ i + 2 ] ) { return false ; } } if ( s [ 0 ] == s [ 1 ] ) return false ; return true ; } let str = " " ; if ( isTwoAlter ( str ) ) document . write ( " " ) ; else document . write ( " " ) ;
Number of character corrections in the given strings to make them equal | Function to return the count of operations required ; To store the count of operations ; No operation required ; One operation is required when any two characters are equal ; Two operations are required when none of the characters are equal ; Return the minimum count of operations required ; Driver code
function minOperations ( n , a , b , c ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let x = a [ i ] ; let y = b [ i ] ; let z = c [ i ] ; if ( x == y && y == z ) { ; } else if ( x == y y == z x == z ) { ans ++ ; } else { ans += 2 ; } } return ans ; } let a = " " ; let b = " " ; let c = " " ; let n = a . length ; document . write ( minOperations ( n , a , b , c ) ) ;
Check if string can be made lexicographically smaller by reversing any substring | Function that returns true if s can be made lexicographically smaller by reversing a sub - string in s ; Traverse in the string ; Check if s [ i + 1 ] < s [ i ] ; Not possible ; Driver code
function check ( s ) { let n = s . length ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( s [ i ] > s [ i + 1 ] ) return true ; } return false ; } let s = " " ; if ( check ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;
Count of sub | Function to return the count of required sub - strings ; Number of sub - strings from position of current x to the end of str ; To store the number of characters before x ; Driver code
function countSubStr ( str , n , x ) { let res = 0 , count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == x ) { res += ( ( count + 1 ) * ( n - i ) ) ; count = 0 ; } else count ++ ; } return res ; } let str = " " ; let n = str . length ; let x = ' ' ; document . write ( countSubStr ( str , n , x ) ) ;
Count of sub | Function to return the count of possible sub - strings of length n ; Driver code
function countSubStr ( str , n ) { var len = str . length ; return len - n + 1 ; } var str = " " ; var n = 5 ; document . write ( countSubStr ( str , n ) ) ;
Count of sub | Function to return the number of sub - strings that do not contain the given character c ; Length of the string ; Traverse in the string ; If current character is different from the given character ; Update the number of sub - strings ; Reset count to 0 ; For the characters appearing after the last occurrence of c ; Driver code
function countSubstrings ( s , c ) { var n = s . length ; var cnt = 0 ; var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) != c ) cnt ++ ; else { sum += ( cnt * ( cnt + 1 ) ) / 2 ; cnt = 0 ; } } sum += ( cnt * ( cnt + 1 ) ) / 2 ; return sum ; } var s = " " ; var c = ' ' ; document . write ( countSubstrings ( s , c ) ) ;
Minimize ASCII values sum after removing all occurrences of one character | Function to return the minimized sum ; To store the occurrences of each character of the string ; Update the occurrence ; Calculate the sum ; Get the character which is contributing the maximum value to the sum ; Count of occurrence of the character multiplied by its ASCII value ; Return the minimized sum ; Driver code
function getMinimizedSum ( str , len ) { var i , maxVal = - 2147483648 , sum = 0 ; var occurrences = new Array ( 26 ) . fill ( 0 ) ; for ( i = 0 ; i < len ; i ++ ) { occurrences [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; sum += str [ i ] . charCodeAt ( 0 ) ; } for ( i = 0 ; i < 26 ; i ++ ) { maxVal = Math . max ( maxVal , occurrences [ i ] * ( i + " " . charCodeAt ( 0 ) ) ) ; } return sum - maxVal ; } var str = " " ; var len = str . length ; document . write ( getMinimizedSum ( str , len ) ) ;
Find index i such that prefix of S1 and suffix of S2 till i form a palindrome when concatenated | Function that returns true if s is palindrome ; Function to return the required index ; Copy the ith character in S ; Copy all the character of string s2 in Temp ; Check whether the string is palindrome ; Driver code
function isPalindrome ( s ) { let i = 0 ; let j = s . length - 1 ; while ( i < j ) { if ( s [ i ] != s [ j ] ) return false ; i ++ ; j -- ; } return true ; } function getIndex ( S1 , S2 , n ) { let S = " " ; for ( let i = 0 ; i < n ; i ++ ) { S = S + S1 [ i ] ; let Temp = " " ; for ( let j = i + 1 ; j < n ; j ++ ) Temp += S2 [ j ] ; if ( isPalindrome ( S + Temp ) ) { return i ; } } return - 1 ; } let S1 = " " , S2 = " " ; let n = S1 . length ; document . write ( getIndex ( S1 , S2 , n ) ) ;
Find index i such that prefix of S1 and suffix of S2 till i form a palindrome when concatenated | Function that returns true if the sub - String starting from index i and ending at index j is a palindrome ; Function to get the required index ; Start comparing the two Strings from both ends . ; Break from the loop at first mismatch ; If it is possible to concatenate the Strings to form palindrome , return index ; If remaining part for s2 is palindrome ; If remaining part for s1 is palindrome ; If not possible , return - 1 ; Driver Code
function isPalindrome ( s , i , j ) { while ( i < j ) { if ( s [ i ] != s [ j ] ) return false ; i ++ ; j -- ; } return true ; } function getIndex ( s1 , s2 , len ) { let i = 0 , j = len - 1 ; while ( i < j ) { if ( s1 [ i ] != s2 [ j ] ) { break ; } i ++ ; j -- ; } if ( i == j ) { return i - 1 ; } else if ( isPalindrome ( s2 , i , j ) ) return i - 1 ; else if ( isPalindrome ( s1 , i , j ) ) return j ; return - 1 ; } let s1 = " " , s2 = " " ; let len = s1 . length ; document . write ( getIndex ( s1 , s2 , len ) + " " ) ;
Acronym words | Function to return the number of strings that can be an acronym for other strings ; Frequency array to store the frequency of the first character of every string in the array ; To store the count of required strings ; Current word ; Frequency array to store the frequency of each of the character of the current string ; Check if the frequency of every character in the current string is <= its value in freq [ ] ; First character of the current string ; Driver code
function count_acronym ( n , arr ) { let freq = new Array ( 26 ) ; freq . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) freq [ arr [ i ] [ 0 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; let cnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let st = arr [ i ] ; let num = new Array ( 26 ) ; num . fill ( 0 ) ; for ( let j = 0 ; j < st . length ; j ++ ) num [ st [ j ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; let flag = true ; for ( let j = 1 ; j < 26 ; j ++ ) { if ( num [ j ] > freq [ j ] ) { flag = false ; break ; } } let x = st [ 0 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; if ( freq [ x ] - 1 < num [ x ] ) flag = false ; if ( flag ) cnt ++ ; } return cnt ; } let arr = [ " " , " " , " " , " " , " " ] ; let n = arr . length ; document . write ( count_acronym ( n , arr ) ) ;