codeparrot/xlcost-text-to-code huggingface dataset:
Count of substrings consisting only of vowels | Function to check vowel or not ; Function to find largest string which satisfy condition ; Check if current character is vowel ; Increment count ; Count all possible substrings of calculated length ; Reset the length ; Add remaining possible substrings consisting of vowels occupying last indices of the string ; Driver code
function isvowel ( x ) { return ( x == ' ' x == ' ' x == ' ' x == ' ' x == ' ' ) ; } function CountTotal ( str ) { let ans = 0 ; let n = str . length ; let s = str . split ( ' ' ) ; let cnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isvowel ( s [ i ] ) ) cnt += 1 ; else { ans += ( cnt * ( cnt + 1 ) / 2 ) ; cnt = 0 ; } } if ( cnt != 0 ) ans += ( cnt * ( cnt + 1 ) / 2 ) ; return ans ; } let s = " " ; document . write ( CountTotal ( s ) ) ;
Number formed by flipping all bits to the left of rightmost set bit | JavaScript program to find the integer formed after flipping all bits to the left of the rightmost set bit ; Function to get the total count ; Moving until we get the rightmost set bit ; To get total number of bits in a number ; Function to find the integer formed after flipping all bits to the left of the rightmost set bit ; Find the total count of bits and the rightmost set bit ; XOR given number with the number which has is made up of only totbits set ; To avoid flipping the bits to the right of the set bit , take XOR with the number made up of only set firstbits ; Driver Code
let totCount ; let firstCount ; function getTotCount ( num ) { totCount = 1 ; firstCount = 1 ; let temp = 1 ; while ( ( num & temp ) == 0 ) { temp = temp << 1 ; totCount += 1 ; } firstCount = totCount ; temp = num >> totCount ; while ( temp != 0 ) { totCount += 1 ; temp = temp >> 1 ; } } function flipBitsFromRightMostSetBit ( num ) { getTotCount ( num ) ; let num1 = num ^ ( ( 1 << totCount ) - 1 ) ; num1 = num1 ^ ( ( 1 << firstCount ) - 1 ) ; return num1 ; } let n = 120 ; document . write ( flipBitsFromRightMostSetBit ( n ) ) ;
Longest substring of vowels with no two adjacent alphabets same | Function to check a character is vowel or not ; Function to find length of longest substring consisting only of vowels and no similar adjacent alphabets ; Stores max length of valid subString ; Stores length of current valid subString ; If curr and prev character are not same , include it ; If same as prev one , start new subString from here ; Store max in maxLen ; Driver code
function isVowel ( x ) { return x === " " || x === " " || x === " " || x === " " || x === " " ; } function findMaxLen ( s ) { var maxLen = 0 ; var cur ; if ( isVowel ( s [ 0 ] ) ) maxLen = 1 ; cur = maxLen ; for ( var i = 1 ; i < s . length ; i ++ ) { if ( isVowel ( s [ i ] ) ) { if ( s [ i ] !== s [ i - 1 ] ) cur += 1 ; else cur = 1 ; } else { cur = 0 ; } maxLen = Math . max ( cur , maxLen ) ; } return maxLen ; } var Str = " " ; document . write ( findMaxLen ( Str ) ) ;
Count of non | Iterative Function to calculate base ^ pow in O ( log y ) ; Function to return the count of non palindromic strings ; Count of strings using n characters with repetitions allowed ; Count of palindromic strings ; Count of non - palindromic strings ; Driver Code
function power ( base , pow ) { let res = 1 ; while ( pow > 0 ) { if ( ( pow & 1 ) == 1 ) res = ( res * base ) ; base = ( base * base ) ; pow >>= 1 ; } return res ; } function countNonPalindromicString ( n , m ) { let total = power ( n , m ) ; let palindrome = power ( n , m / 2 + m % 2 ) ; let count = total - palindrome ; return count ; } let n = 3 , m = 5 ; document . write ( countNonPalindromicString ( n , m ) ) ;
Count of K | To store the frequency array ; Function to check palindromic of of any substring using frequency array ; Initialise the odd count ; Traversing frequency array to compute the count of characters having odd frequency ; Returns true if odd count is atmost 1 ; Function to count the total number substring whose any permutations are palindromic ; Computing the frequency of first K character of the string ; To store the count of palindromic permutations ; Checking for the current window if it has any palindromic permutation ; Start and end point of window ; Decrementing count of first element of the window ; Incrementing count of next element of the window ; Checking current window character frequency count ; Return the final count ; Given string str ; Window of size K ; Function Call
var freq = Array ( 26 ) . fill ( 0 ) ; function checkPalindrome ( ) { var oddCnt = 0 ; freq . forEach ( x => { if ( x % 2 == 1 ) oddCnt ++ ; } ) ; return oddCnt <= 1 ; } function countPalindromePermutation ( s , k ) { for ( var i = 0 ; i < k ; i ++ ) { freq [ s [ i ] . charCodeAt ( 0 ) - 97 ] ++ ; } var ans = 0 ; if ( checkPalindrome ( ) ) { ans ++ ; } var i = 0 , j = k ; while ( j < s . length ) { freq [ s [ i ++ ] . charCodeAt ( 0 ) - 97 ] -- ; freq [ s [ j ++ ] . charCodeAt ( 0 ) - 97 ] ++ ; if ( checkPalindrome ( ) ) { ans ++ ; } } return ans ; } var str = " " ; var K = 3 ; document . write ( countPalindromePermutation ( str , K ) ) ;
Minimum flips required to form given binary string where every flip changes all bits to its right as well | Function to return the count of minimum flips required ; If curr occurs in the final string ; Switch curr to '0' if '1' or vice - versa ; Driver code
function minFlips ( target ) { let curr = ' ' ; let count = 0 ; for ( let i = 0 ; i < target . length ; i ++ ) { if ( target [ i ] == curr ) { count ++ ; curr = String . fromCharCode ( 48 + ( curr . charCodeAt ( ) + 1 ) % 2 ) ; } } return count ; } let S = " " ; document . write ( minFlips ( S ) ) ;
Check if a number ends with another number or not | Function to check if B is a suffix of A or not ; Find the number of digit in B ; Subtract B from A ; Returns true , if B is a suffix of A ; Given numbers ; Function call ; If B is a suffix of A , then print " Yes "
function checkSuffix ( A , B ) { let digit_B = parseInt ( Math . log10 ( B ) + 1 , 10 ) ; A -= B ; return ( A % ( Math . pow ( 10 , digit_B ) ) > 0 ) ; } let A = 12345 , B = 45 ; let result = checkSuffix ( A , B ) ; if ( ! result ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Minimum length of substring whose rotation generates a palindromic substring | Function to return the minimum length of substring ; Store the index of previous occurrence of the character ; Variable to store the maximum length of substring ; If the current character hasn 't appeared yet ; If the character has occured within one or two previous index , a palindromic substring already exists ; Update the maximum ; Replace the previous index of the character by the current index ; If character appeared at least twice ; Driver code
function count_min_length ( s ) { var hash = new Array ( 26 ) . fill ( 0 ) ; var ans = 2147483648 ; for ( var i = 0 ; i < 26 ; i ++ ) hash [ i ] = - 1 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( hash [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] == - 1 ) hash [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = i ; else { if ( hash [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] == i - 1 || hash [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] == i - 2 ) return 0 ; ans = Math . min ( ans , i - hash [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] - 1 ) ; hash [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = i ; } } if ( ans === 2147483648 ) return - 1 ; return ans ; } var str = " " ; document . write ( count_min_length ( str ) ) ;
Program to remove HTML tags from a given String | Function to remove the HTML tags from the given string ; Use regex_replace function in regex to erase every tags enclosed in < > ; Print string after removing tags ; Given String ; Function call to print the HTML string after removing tags
function RemoveHTMLTags ( s ) { const pattern = new RegExp ( " \\ \\ " ) ; s = new String ( s ) . replace ( pattern , " " ) ; document . write ( s ) ; return ; } let str = " " ; RemoveHTMLTags ( str ) ;
Move all occurrence of letter ' x ' from the string s to the end using Recursion | Recursive program to bring ' x ' to the end ; When the string is completed from reverse direction end of recursion ; If the character x is found ; Transverse the whole string ; Swap the x so that it moves to the last ; call to the smaller problem now ; Driver code ; Size of a ; Call to rec
function rec ( a , i ) { if ( i == 0 ) { document . write ( a . join ( " " ) ) ; return ; } if ( a [ i ] == ' ' ) { let j = i ; while ( a [ j ] != ' \0 ' && a [ j + 1 ] != ' \0 ' ) { let temp = a [ j ] ; a [ j ] = a [ j + 1 ] ; a [ j + 1 ] = temp ; j ++ ; } } rec ( a , i - 1 ) ; } let a = [ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' \0 ' ] ; let n = 10 ; rec ( a , n - 1 ) ;
Find the largest Alphabetic character present in the string | Function to find the Largest Alphabetic Character ; Array for keeping track of both uppercase and lowercase english alphabets ; Iterate from right side of array to get the largest index character ; Check for the character if both its uppercase and lowercase exist or not ; Return - 1 if no such character whose uppercase and lowercase present in string str ; Driver code
function largestCharacter ( str ) { let uppercase = new Array ( 26 ) ; uppercase . fill ( false ) ; let lowercase = new Array ( 26 ) ; lowercase . fill ( false ) ; let arr = str . split ( ' ' ) ; for ( let c = 0 ; c < arr . length ; c ++ ) { if ( arr == arr . toLowerCase ( ) ) lowercase [ arr . charCodeAt ( ) - 97 ] = true ; if ( arr == arr . toUpperCase ( ) ) uppercase [ arr . charCodeAt ( ) - 65 ] = true ; } for ( let i = 25 ; i >= 0 ; i -- ) { if ( uppercase [ i ] && lowercase [ i ] ) return String . fromCharCode ( i + ' ' . charCodeAt ( ) ) + " " ; } return " " ; } let str = " " ; document . write ( largestCharacter ( str ) ) ;
Generate a string of size N whose each substring of size M has exactly K distinct characters | Function to generate the String ; Declare empty string ; counter for M ; counter for K ; Loop to generate string size of N ; Generating K distinct letters one by one ; After generating b distinct letters , append rest a - b letters as ' a ' ; Reset the counter value and repeat the process ; return final result string ; Driver code
function generateString ( N , M , K ) { let s = " " ; let cnt1 = 0 ; let cnt2 = 0 ; for ( let i = 0 ; i < N ; i ++ ) { cnt1 ++ ; cnt2 ++ ; if ( cnt1 <= M ) { if ( cnt2 <= K ) { s = s + String . fromCharCode ( 96 + cnt1 ) ; } else { s = s + ' ' ; } } else { cnt1 = 1 ; cnt2 = 1 ; s = s + ' ' ; } } return s ; } let N = 7 , M = 5 , K = 3 ; document . write ( generateString ( N , M , K ) )
Print string after removing all ( “ 10 ” or “ 01 ” ) from the binary string | Function to print the final String after removing all the occurrences of "10" and "01" from the given binary String ; Variables to store the count of 1 ' s ▁ and ▁ 0' s ; Variable left will store whether 0 ' s ▁ or ▁ 1' s is left in the final String ; Length of the String ; For loop to count the occurrences of 1 ' s ▁ and ▁ 0' s in the String ; To check if the count of 1 ' s ▁ is ▁ ▁ greater ▁ than ▁ the ▁ count ▁ of ▁ 0' s or not . If x is greater , then those many 1 's  are prleted. ; Length of the final remaining String after removing all the occurrences ; Printing the final String ; Driver Code
function finalString ( str ) { let x = 0 , y = 0 ; let left ; let n = str . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' ) x ++ ; else y ++ ; } if ( x > y ) left = 1 ; else left = 0 ; let length = n - 2 * Math . min ( x , y ) ; for ( let i = 0 ; i < length ; i ++ ) { document . write ( left ) ; } } let str = " " ; finalString ( str ) ;
Lexicographically smaller string by swapping at most one character pair | Swap function ; Function that finds whether is it possible to make String A lexicographically smaller than String B ; Condition if String A is already smaller than B ; Sorting temp String ; Condition for first changed character of String A and temp ; Condition if String A is already sorted ; Finding first changed character from last of String A ; Swap the two characters ; Condition if String A is smaller than B ; Driver Code
function swap ( str , i , j ) { let tempArr = str . split ( " " ) ; let temp = tempArr [ i ] ; tempArr [ i ] = tempArr [ j ] ; tempArr [ j ] = temp ; return ( tempArr ) . join ( " " ) ; } function IsLexicographicallySmaller ( A , B ) { if ( A < ( B ) ) { return true ; } let temp = A ; let p = temp . split ( " " ) ; p . sort ( ) ; temp = ( p ) . join ( " " ) ; let index = - 1 ; for ( let i = 0 ; i < A . length ; i ++ ) { if ( A [ i ] != temp [ i ] ) { index = i ; break ; } } if ( index == - 1 ) { return false ; } let j = 0 ; for ( let i = 0 ; i < A . length ; i ++ ) { if ( A [ i ] == temp [ index ] ) j = i ; } A = swap ( A , index , j ) ; if ( A < ( B ) ) { return true ; } else { return false ; } } let A = " " ; let B = " " ; if ( IsLexicographicallySmaller ( A , B ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }
Length of longest palindromic sub | Function to find maximum of the two variables ; Function to find the longest palindromic subString : Recursion ; Base condition when the start index is greater than end index ; Base condition when both the start and end index are equal ; Condition when corner characters are equal in the String ; Recursive call to find the longest Palindromic String by excluding the corner characters ; Recursive call to find the longest Palindromic String by including one corner character at a time ; Function to find the longest palindromic sub - String ; Utility function call ; Driver Code ; Function Call
function max ( x , y ) { return ( x > y ) ? x : y ; } function longestPalindromic ( str , i , j , count ) { if ( i > j ) return count ; if ( i == j ) return ( count + 1 ) ; if ( str [ i ] == str [ j ] ) { count = longestPalindromic ( str , i + 1 , j - 1 , count + 2 ) ; return max ( count , max ( longestPalindromic ( str , i + 1 , j , 0 ) , longestPalindromic ( str , i , j - 1 , 0 ) ) ) ; } return Math . max ( longestPalindromic ( str , i + 1 , j , 0 ) , longestPalindromic ( str , i , j - 1 , 0 ) ) ; } function longest_palindromic_substr ( str ) { return longestPalindromic ( str , 0 , str . length - 1 , 0 ) ; } let str = " " ; document . write ( longest_palindromic_substr ( str ) ) ;
Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency | Function to find the maximum possible prefix of the s ; Hash map to store the frequency of the characters in the s ; Iterate over the s to find the occurence of each Character ; Minimum frequency of the Characters ; Loop to find the count of minimum frequency in the hash - map ; Loop to find the maximum possible length of the prefix in the s ; Condition to check if the frequency is greater than minimum possible freq ; maxprefix s and its length . ; Driver Code s is initialize . ; str is passed in MaxPrefix function .
function MaxPrefix ( s ) { var Dict = { } ; for ( const i of s ) { if ( Dict . hasOwnProperty ( i ) ) { Dict [ i ] ++ ; } else { Dict [ i ] = 1 ; } } var minfrequency = 2147483647 ; for ( const [ key , value ] of Object . entries ( Dict ) ) { minfrequency = Math . min ( minfrequency , value ) ; } var countminFrequency = 0 ; for ( const [ key , value ] of Object . entries ( Dict ) ) { if ( Dict [ key ] === minfrequency ) countminFrequency += 1 ; } var mapper = { } ; var indi = 0 ; for ( const i of s ) { if ( mapper . hasOwnProperty ( i ) ) { mapper [ i ] ++ ; } else { mapper [ i ] = 1 ; } if ( mapper [ i ] > countminFrequency ) break ; indi += 1 ; } document . write ( s . substring ( 0 , indi ) ) ; } var str = " " ; MaxPrefix ( str ) ;
Count of Substrings that can be formed without using the given list of Characters | Function to find the Number of sub - Strings without using given character ; Mark the given characters in the freq array ; Count variable to store the count of the characters until a character from given L is encountered ; If a character from L is encountered , then the answer variable is incremented by the value obtained by using the mentioned formula and count is set to 0 ; For last remaining characters ; Driver code
function countSubString ( S , L , n ) { var freq = new Array ( 26 ) . fill ( 0 ) ; var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { freq [ L [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = 1 ; } var count = 0 ; for ( const x of S ) { if ( freq [ x . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] > 0 ) { ans = ans + parseInt ( ( count * count + count ) / 2 ) ; count = 0 ; } else count ++ ; } ans += parseInt ( ( count * count + count ) / 2 ) ; return ans ; } var S = " " ; var L = [ " " , " " , " " ] ; var n = L . length ; document . write ( countSubString ( S . split ( " " ) , L , n ) ) ;
Program to accept Strings starting with a Vowel | Function to check if first character is vowel ; Function to check ; Driver code
function checkIfStartsWithVowels ( str ) { if ( ! ( str [ 0 ] == ' ' str [ 0 ] == ' ' str [ 0 ] == ' ' str [ 0 ] == ' ' str [ 0 ] == ' ' str [ 0 ] == ' ' str [ 0 ] == ' ' str [ 0 ] == ' ' str [ 0 ] == ' ' str [ 0 ] == ' ' ) ) return 1 ; else return 0 ; } function check ( str ) { if ( checkIfStartsWithVowels ( str ) ) document . write ( " " ) ; else document . write ( " " ) ; } var str = " " ; check ( str ) ; str = " " ; check ( str ) ;
Find the Nth occurrence of a character in the given String | Function to find the Nth occurrence of a character ; Loop to find the Nth occurrence of the character ; Driver Code
function findNthOccur ( str , ch , N ) { var occur = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ch ) { occur += 1 ; } if ( occur == N ) return i ; } return - 1 ; } var str = " " ; var ch = ' ' ; var N = 2 ; document . write ( findNthOccur ( str , ch , N ) ) ;
Longest equal substring with cost less than K | Function to find the maximum length ; Fill the prefix array with the difference of letters ; Update the maximum length ; Driver code
function solve ( X , Y , N , K ) { let count = new Array ( N + 1 ) ; count . fill ( 0 ) ; let sol = 0 ; count [ 0 ] = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { count [ i ] = count [ i - 1 ] + Math . abs ( X [ i - 1 ] . charCodeAt ( ) - Y [ i - 1 ] . charCodeAt ( ) ) ; } let j = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { while ( ( count [ i ] - count [ j ] ) > K ) { j ++ ; } sol = Math . max ( sol , i - j ) ; } return sol ; } let N = 4 ; let X = " " , Y = " " ; let K = 3 ; document . write ( solve ( X , Y , N , K ) ) ;
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 ; Jaro Winkler Similarity ; If the jaro Similarity is above a threshold ; Find the length of common prefix ; If the characters match ; Else break ; Maximum of 4 characters are allowed in prefix ; Calculate jaro winkler Similarity ; Driver code ; Print Jaro - Winkler Similarity of two strings
function jaro_distance ( s1 , s2 ) { if ( s1 == s2 ) return 1.0 ; let len1 = s1 . length , len2 = s2 . length ; if ( len1 == 0 len2 == 0 ) return 0.0 ; let max_dist = Math . floor ( Math . max ( len1 , len2 ) / 2 ) - 1 ; let match = 0 ; let hash_s1 = new Array ( s1 . length ) ; hash_s1 . fill ( 0 ) ; let hash_s2 = new Array ( s2 . length ) ; hash_s2 . fill ( 0 ) ; for ( let i = 0 ; i < len1 ; i ++ ) { for ( let 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 ; let t = 0 ; let point = 0 ; for ( let i = 0 ; i < len1 ; i ++ ) if ( hash_s1 [ i ] == 1 ) { while ( hash_s2 [ point ] == 0 ) point ++ ; if ( s1 [ i ] != s2 [ point ++ ] ) t ++ ; } t /= 2 ; return ( ( match ) / ( len1 ) + ( match ) / ( len2 ) + ( match - t ) / ( match ) ) / 3.0 ; } function jaro_Winkler ( s1 , s2 ) { let jaro_dist = jaro_distance ( s1 , s2 ) ; if ( jaro_dist > 0.7 ) { let prefix = 0 ; for ( let i = 0 ; i < Math . min ( s1 . length , s2 . length ) ; i ++ ) { if ( s1 [ i ] == s2 [ i ] ) prefix ++ ; else break ; } prefix = Math . min ( 4 , prefix ) ; jaro_dist += 0.1 * prefix * ( 1 - jaro_dist ) ; } return jaro_dist . toFixed ( 6 ) ; } let s1 = " " , s2 = " " ; document . write ( " " + jaro_Winkler ( s1 , s2 ) ) ;
Check if a word is present in a sentence | Function that returns true if the word is found ; To break the sentence in words ; To temporarily store each individual word ; Comparing the current word with the word to be searched ; Driver code
function isWordPresent ( sentence , word ) { let s = sentence . split ( " " ) ; for ( let temp = 0 ; temp < s . length ; temp ++ ) { if ( s [ temp ] == ( word ) ) { return true ; } } return false ; } let s = " " ; let word = " " ; if ( isWordPresent ( s , word ) ) document . write ( " " ) ; else document . write ( " " ) ;
Check if a word is present in a sentence | Function that returns true if the word is found ; To convert the word in uppercase ; To convert the complete sentence in uppercase ; To break the sentence in words ; To store the individual words of the sentence ; Comparing the current word with the word to be searched ; Driver code
function isWordPresent ( sentence , word ) { word = transform ( word ) ; sentence = transform ( sentence ) ; let s = sentence . split ( " " ) ; for ( let temp = 0 ; temp < s . length ; temp ++ ) { if ( s [ temp ] == ( word ) ) { return true ; } } return false ; } function transform ( word ) { return word . toUpperCase ( ) ; } let s = " " ; let word = " " ; if ( isWordPresent ( s , word ) ) document . write ( " " ) ; else document . write ( " " ) ;
Count of 1 | Function to return the count of required characters ; While there are characters left ; Single bit character ; Two - bit character ; Update the count ; Driver code
function countChars ( str , n ) { let i = 0 , cnt = 0 ; while ( i < n ) { if ( str [ i ] == ' ' ) i += 1 ; else i += 2 ; cnt += 1 ; } return cnt ; } let str = " " ; let n = str . length ; document . write ( countChars ( str , n ) ) ;
Print the frequency of each character in Alphabetical order | Javascript implementation of the approach ; Function to print the frequency of each of the characters of s in alphabetical order ; To store the frequency of the characters ; Update the frequency array ; Print the frequency in alphatecial order ; If the current alphabet doesn 't  appear in the string ; Driver code
let MAX = 26 ; function compressString ( s , n ) { let freq = new Array ( MAX ) ; freq . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { freq [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; } for ( let i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] == 0 ) continue ; document . write ( String . fromCharCode ( i + ' ' . charCodeAt ( ) ) + " " + freq [ i ] ) ; } } let s = " " ; let n = s . length ; compressString ( s , n ) ;