codeparrot/xlcost-text-to-code huggingface dataset:
Rearrange a string to maximize the minimum distance between any pair of vowels | Function to rearrange the string such that the minimum distance between any of vowels is maximum . ; Store vowels and consonants ; Iterate over the characters of string ; If current character is a vowel ; If current character is a consonant ; Stores count of vowels and consonants respectively ; Stores the resultant string ; Stores count of consonants appended into ans ; Append vowel to ans ; Append consonants ; Append consonant to ans ; Update temp ; Remove the taken elements of consonant ; Return final ans ; Driver Code ; Function Call
function solution ( s ) { var vowel = [ ] , consonant = [ ] ; s . split ( ' ' ) . forEach ( i => { if ( i == ' ' i == ' ' i == ' ' i == ' ' i == ' ' ) { vowel . push ( i ) ; } else { consonant . push ( i ) ; } } ) ; var Nc , Nv ; Nv = vowel . length ; Nc = consonant . length ; var M = parseInt ( Nc / ( Nv - 1 ) ) ; var ans = " " ; var consotnant_till = 0 ; vowel . forEach ( i => { ans += i ; var temp = 0 ; for ( var j = consotnant_till ; j < Math . min ( Nc , consotnant_till + M ) ; j ++ ) { ans += consonant [ j ] ; temp ++ ; } consotnant_till += temp ; } ) ; return ans ; } var str = " " ; document . write ( solution ( str ) ) ;
Lexicographically smallest string possible by performing K operations on a given string | Function to find the lexicographically smallest possible string by performing K operations on string S ; Store the size of string , s ; Check if k >= n , if true , convert every character to ' a ' ; Iterate in range [ 0 , n - 1 ] using i ; When k reaches 0 , break the loop ; If current character is ' a ' , continue ; Otherwise , iterate in the range [ i + 1 , n - 1 ] using j ; Check if s [ j ] > s [ i ] ; If true , set s [ j ] = s [ i ] and break out of the loop ; Check if j reaches the last index ; Update S [ i ] ; Decrement k by 1 ; Print string ; Given String , s ; Given k ; Function Call
function smallestlexicographicstring ( s , k ) { let n = s . length ; if ( k >= n ) { for ( let i = 0 ; i < n ; i ++ ) { s [ i ] = ' ' ; } document . write ( s ) ; return ; } for ( let i = 0 ; i < n ; i ++ ) { if ( k == 0 ) { break ; } if ( s [ i ] == ' ' ) continue ; for ( let j = i + 1 ; j < n ; j ++ ) { if ( s [ j ] . charCodeAt ( ) > s [ i ] . charCodeAt ( ) ) { s [ j ] = s [ i ] ; break ; } else if ( j == n - 1 ) s [ j ] = s [ i ] ; } s [ i ] = ' ' ; k -- ; } document . write ( s . join ( " " ) ) ; } let s = ( " " ) . split ( ' ' ) ; let k = 6 ; smallestlexicographicstring ( s , k ) ;
Minimize removal of non | Function to find minimum count of steps required ot make string S an empty string ; Stores count of occurences ' ( ' ; Stores count of occurences ' ) ' ; Traverse the string , str ; If current character is ' ( ' ; Update count_1 ; Update count_2 ; If all the characters are same , then print - 1 ; If the count of occurence of ' ) ' and ' ( ' are same then print 0 ; If length of string is Odd ; Given string ; Size of the string ; Function Call
function canReduceString ( S , N ) { var count_1 = 0 ; var count_2 = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( S [ i ] === " " ) { count_1 ++ ; } else { count_2 ++ ; } } if ( count_1 === 0 count_2 === 0 ) { document . write ( " " + " " ) ; } else if ( count_1 === count_2 ) { document . write ( " " + " " ) ; } else if ( N % 2 !== 0 ) { document . write ( " " ) ; } else { document . write ( Math . abs ( count_1 - count_2 ) / 2 ) ; } } var S = " " ; var N = S . length ; canReduceString ( S , N ) ;
Program to construct a DFA which accepts the language L = { aN | N â ‰¥ 1 } | Function to check whether the String S satisfy the given DFA or not ; Stores the count of characters ; Iterate over the range [ 0 , N ] ; Count and check every element for ' a ' ; If String matches with DFA ; If not matches ; Driver Code ; Function Call
function isAcceptedDFA ( s , N ) { var count = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( s [ i ] === " " ) count ++ ; } if ( count === N && count !== 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var S = " " ; isAcceptedDFA ( S , S . length ) ;
Maximize palindromic strings of length 3 possible from given count of alphabets | Function to count maximum number of palindromic string of length 3 ; Stores the final count of palindromic strings ; Traverse the array ; Increment res by arr [ i ] / 3 , i . e forming string of only i + ' a ' character ; Store remainder ; Increment c1 by one , if current frequency is 1 ; Increment c2 by one , if current frequency is 2 ; Count palindromic strings of length 3 having the character at the ends different from that present in the middle ; Update c1 and c2 ; Increment res by 2 * c2 / 3 ; Finally print the result ; Given array ; Function Call
function maximum_pallindromic ( arr ) { var res = 0 ; var c1 = 0 , c2 = 0 ; for ( var i = 0 ; i < 26 ; i ++ ) { res += parseInt ( arr [ i ] / 3 ) ; arr [ i ] = ( arr [ i ] % 3 ) ; if ( arr [ i ] == 1 ) c1 ++ ; else if ( arr [ i ] == 2 ) c2 ++ ; } res += Math . min ( c1 , c2 ) ; var t = Math . min ( c1 , c2 ) ; c1 -= t ; c2 -= t ; res += 2 * parseInt ( c2 / 3 ) ; c2 %= 3 ; res += parseInt ( c2 / 2 ) ; document . write ( res ) ; } var arr = [ 4 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ; maximum_pallindromic ( arr ) ;
Find the winner of game of repeatedly removing the first character to empty given string | Function to find the winner of a game of repeatedly removing the first character to empty a string ; Store characters of each string of the array arr [ ] ; Stores count of strings in arr [ ] ; Traverse the array arr [ ] ; Stores length of current string ; Traverse the string ; Insert arr [ i ] [ j ] ; 1 st Player starts the game ; Stores the player number for the next turn ; Remove 1 st character of current string ; Update player number for the next turn ; Driver Code
function find_Winner ( arr , N ) { var Q = Array . from ( Array ( N ) , ( ) => Array ( ) ) var M = arr . length ; for ( var i = 0 ; i < M ; i ++ ) { var len = arr [ i ] . length ; for ( var j = 0 ; j < len ; j ++ ) { Q [ i ] . push ( arr [ i ] [ j ] - 1 ) ; } } var player = 0 ; while ( Q [ player ] . length > 0 ) { var nextPlayer = Q [ player ] [ 0 ] - ' ' ; Q [ player ] . shift ( ) ; player = nextPlayer ; } document . write ( " " + ( player + 1 ) ) ; } var N = 3 ; var arr = [ " " , " " , " " ] ; find_Winner ( arr , N ) ;
Longest Substring that can be made a palindrome by swapping of characters | Function to find the Longest substring that can be made a palindrome by swapping of characters ; Initialize dp array of size 1024 ; Initializing mask and res ; Traverse the string ; Find the mask of the current character ; Finding the length of the longest substring in s which is a palindrome for even count ; Finding the length of the longest substring in s which is a palindrome for one odd count ; Finding maximum length of substring having one odd count ; dp [ mask ] is minimum of current i and dp [ mask ] ; Return longest length of the substring which forms a palindrome with swaps ; Input String ; Function Call
function longestSubstring ( s ) { let dp = new Array ( 1024 ) . fill ( 1 ) ; let res = 0 , mask = 0 ; dp [ 0 ] = - 1 ; for ( let i = 0 ; i < s . length ; ++ i ) { mask ^= 1 << ( s [ i ] - ' ' ) ; res = Math . max ( res , i - dp [ mask ] ) ; for ( let j = 0 ; j <= 9 ; ++ j ) res = Math . max ( res , i - dp [ mask ^ ( 1 << j ) ] ) ; dp [ mask ] = Math . min ( dp [ mask ] , i ) ; } return res ; } let s = " " ; document . write ( longestSubstring ( s ) ) ;
Convert given string to a valid mobile number | Function to print the valid and formatted phone number ; Length of given String ; Store digits in temp ; Iterate given M ; If any digit , append it to temp ; Find new length of String ; If length is not equal to 10 ; Store final result ; Make groups of 3 digits and enclose them within ( ) and separate them with " - " 0 to 2 index 1 st group ; 3 to 5 index 2 nd group ; 6 to 8 index 3 rd group ; 9 to 9 index last group ; Print final result ; Given String ; Function Call
function Validate ( M ) { let len = M . length ; let temp = " " ; for ( let i = 0 ; i < len ; i ++ ) { if ( ! isNaN ( parseInt ( M [ i ] ) ) ) temp += M [ i ] ; } let nwlen = temp . length ; if ( nwlen != 10 ) { document . write ( " " ) ; return ; } let res = " " ; let x = temp . substring ( 0 , 3 ) ; res += " " + x + " " ; x = temp . substring ( 3 , 6 ) ; res += " " + x + " " ; x = temp . substring ( 6 , 9 ) ; res += " " + x + " " ; x = temp . substring ( 9 , 10 ) ; res += " " + x + " " ; document . write ( res + " " ) ; } let M = " " ; Validate ( M ) ;
Modulus of two Hexadecimal Numbers | Function to calculate modulus of two Hexadecimal numbers ; Store all possible hexadecimal digits ; Iterate over the range [ '0' , '9' ] ; Convert given string to long ; Base to get 16 power ; Store N % K ; Iterate over the digits of N ; Stores i - th digit of N ; Update ans ; Update base ; Print the answer converting into hexadecimal ; Given string N and K ; Function Call
function hexaModK ( s , k ) { var mp = new Map ( ) ; for ( var i = 1 ; i <= 9 ; i ++ ) { mp . set ( String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) , i ) ; } mp . set ( ' ' , 10 ) ; mp . set ( ' ' , 11 ) ; mp . set ( ' ' , 12 ) ; mp . set ( ' ' , 13 ) ; mp . set ( ' ' , 14 ) ; mp . set ( ' ' , 15 ) ; var m = parseInt ( k , 16 ) ; var base = 1 ; var ans = 0 ; for ( var i = s . length - 1 ; i >= 0 ; i -- ) { var n = mp . get ( s [ i ] ) % m ; ans = ( ans + ( base % m * n % m ) % m ) % m ; base = ( base % m * 16 % m ) % m ; } document . write ( ans . toString ( 16 ) . toUpperCase ( ) ) ; } var n = " " ; var k = " " ; hexaModK ( n , k ) ;
Print all combinations generated by characters of a numeric string which does not exceed N | Store the current sequence of s ; Store the all the required sequences ; Function to print all sequences of S satisfying the required condition ; Print all Strings in the set ; Function to generate all sequences of String S that are at most N ; Iterate over String s ; Push ith character to combination ; Convert the String to number ; Check if the condition is true ; Push the current String to the readonly set of sequences ; Recursively call function ; Backtrack to its previous state ; Driver Code ; Function Call ; Print required sequences
var combination = " " ; var combinations = [ ] ; function printSequences ( combinations ) { for ( var s of combinations ) { document . write ( s + " " ) ; } } function generateCombinations ( s , n ) { for ( var i = 0 ; i < s . length ; i ++ ) { combination += s [ i ] ; var x = parseInt ( combination ) ; if ( x <= n ) { combinations . push ( combination ) ; generateCombinations ( s , n ) ; } combination = combination . substring ( 0 , combination . length - 1 ) ; } } var S = " " ; var N = 100 ; generateCombinations ( S , N ) ; printSequences ( combinations ) ;
Count Distinct Strings present in an array using Polynomial rolling hash function | Function to find the hash value of a string ; Traverse the string ; Update hash_val ; Update mul ; Return hash_val of str ; Function to find the count of distinct strings present in the given array ; Store the hash values of the strings ; Traverse the array ; Stores hash value of arr [ i ] ; Sort hash [ ] array ; Stores count of distinct strings in the array ; Traverse hash [ ] array ; Update cntElem ; Driver Code
function compute_hash ( str ) { let p = 31 ; let MOD = 1e9 + 7 ; let hash_val = 0 ; let mul = 1 ; for ( let i = 0 ; i < str . length ; i ++ ) { let ch = str [ i ] ; hash_val = ( hash_val + ( ch . charCodeAt ( ) - ' ' . charCodeAt ( ) + 1 ) * mul ) % MOD ; mul = ( mul * p ) % MOD ; } return hash_val ; } function distinct_str ( arr , n ) { let hash = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { hash [ i ] = compute_hash ( arr [ i ] ) ; } hash . sort ( function ( a , b ) { return a - b } ) ; let cntElem = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( hash [ i ] != hash [ i - 1 ] ) { cntElem ++ ; } } return cntElem ; } let arr = [ " " , " " , " " , " " ] ; let N = arr . length ; document . write ( distinct_str ( arr , N ) ) ;
Remove characters from given string whose frequencies are a Prime Number | Function to perform the seive of eratosthenes algorithm ; Initialize all entries in prime [ ] as true ; Initialize 0 and 1 as non prime ; Traversing the prime array ; If i is prime ; All multiples of i must be marked false as they are non prime ; Function to remove characters which have prime frequency in the string ; Length of the string ; Create a boolean array prime ; Sieve of Eratosthenes ; Stores the frequency of character ; Storing the frequencies ; New string that will be formed ; Removing the characters which have prime frequencies ; If the character has prime frequency then skip ; Else concatenate the character to the new string ; Print the modified string ; Driver Code ; Function Call
function SieveOfEratosthenes ( prime , n ) { for ( let i = 0 ; i <= n ; i ++ ) { prime [ i ] = true ; } prime [ 0 ] = prime [ 1 ] = false ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == true ) { for ( let j = 2 ; i * j <= n ; j ++ ) { prime [ i * j ] = false ; } } } } function removePrimeFrequencies ( s ) { var n = s . length ; var prime = new Array ( n + 1 ) ; SieveOfEratosthenes ( prime , n ) ; var m = { } ; for ( let i = 0 ; i < s . length ; i ++ ) m [ s [ i ] ] = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { m [ s [ i ] ] ++ ; } var new_string = " " ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( prime [ m [ s [ i ] ] ] ) continue ; new_string += s [ i ] ; } console . log ( new_string ) ; } str = " " ; removePrimeFrequencies ( str ) ;
Rearrange string such that no pair of adjacent characters are of the same type | Function to rearrange given alphanumeric String such that no two adjacent characters are of the same type ; Stores alphabets and digits ; Store the alphabets and digits separately in the Strings ; Stores the count of alphabets and digits ; If respective counts differ by 1 ; Desired arrangement not possible ; Stores the indexes ; Check if first character should be alphabet or digit ; Place alphabets and digits alternatively ; If current character needs to be alphabet ; If current character needs to be a digit ; Flip flag for alternate arrangement ; Return resultant String ; Given String ; Function Call
function rearrange ( s ) { let s1 = " " , s2 = " " , ans = " " ; let s3 = s . split ( " " ) ; for ( let x = 0 ; x < s3 . length ; x ++ ) { if ( s3 [ x ] >= ' ' && s3 [ x ] <= ' ' ) s1 += s3 [ x ] ; else s2 += s3 [ x ] ; } let n = s1 . length ; let m = s2 . length ; if ( Math . abs ( n - m ) > 1 ) return " " ; let i = 0 , j = 0 , k = 0 ; let flag = ( n >= m ) ? 1 : 0 ; while ( i < n && j < m ) { if ( flag != 0 ) ans += s1 [ i ++ ] ; else ans += s2 [ j ++ ] ; if ( flag == 1 ) flag = 0 ; else flag = 1 ; } return ans ; } let str = " " ; document . write ( rearrange ( str ) + " " ) ;
Find value after N operations to remove N characters of string S with given constraints | Function to find the value after N operations to remove all the N characters of String S ; Iterate till N ; Remove character at ind and decrease n ( size of String ) ; Increase count by ind + 1 ; Given String str ; Function call
function charactersCount ( str , n ) { let count = 0 ; while ( n > 0 ) { let cur = str [ 0 ] . charCodeAt ( ) ; let ind = 0 ; for ( let j = 1 ; j < n ; j ++ ) { if ( str [ j ] . charCodeAt ( ) < cur ) { cur = str [ j ] . charCodeAt ( ) ; ind = j ; } } str = str . substring ( 0 , ind ) + str . substring ( ind + 1 ) ; n -- ; count += ind + 1 ; } document . write ( count + " " ) ; } let str = " " ; let n = 5 ; charactersCount ( str , n ) ;
Print the middle character of a string | Function that prints the middle character of a string ; Finding string length ; Finding middle index of string ; Print the middle character of the string ; Given string str ; Function Call
function printMiddleCharacter ( str ) { let len = str . length ; let middle = parseInt ( len / 2 , 10 ) ; document . write ( str [ middle ] ) ; } let str = " " ; printMiddleCharacter ( str ) ;
Maximize length of the String by concatenating characters from an Array of Strings | Function to check if all the string characters are unique ; Check for repetition in characters ; Function to generate all possible strings from the given array ; Base case ; Consider every string as a starting substring and store the generated string ; Add current string to result of other strings and check if characters are unique or not ; Function to find the maximum possible length of a string ; Return max length possible ; Return the answer ; Driver Code
function check ( s ) { let a = new Set ( ) ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( a . has ( s [ i ] ) ) { return false ; } a . add ( s [ i ] ) ; } return true ; } function helper ( arr , ind ) { let fin = [ ] ; fin . push ( " " ) ; if ( ind == arr . length ) return fin ; let tmp = helper ( arr , ind + 1 ) ; let ret = tmp ; for ( let i = 0 ; i < tmp . length ; i ++ ) { let test = tmp [ i ] + arr [ ind ] ; if ( check ( test ) ) ret . push ( test ) ; } return ret ; } function maxLength ( arr ) { let tmp = helper ( arr , 0 ) ; let len = 0 ; for ( let i = 0 ; i < tmp . length ; i ++ ) { len = len > tmp [ i ] . length ? len : tmp [ i ] . length ; } return len ; } let s = [ ] ; s . push ( " " ) ; document . write ( maxLength ( s ) ) ;
Perform range sum queries on string as per given condition | Function to perform range sum queries on string as per the given condition ; Initialize N by string size ; Create array A [ ] for prefix sum ; Iterate till N ; Traverse the queries ; Check if if L == 1 range sum will be A [ R - 1 ] ; Condition if L > 1 range sum will be A [ R - 1 ] - A [ L - 2 ] ; Given string ; Given Queries ; Function call
function Range_sum_query ( S , Query ) { var N = S . length ; var A = Array ( N ) ; A [ 0 ] = S [ 0 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 1 ; for ( var i = 1 ; i < N ; i ++ ) { A [ i ] = S [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 1 ; A [ i ] = A [ i ] + A [ i - 1 ] ; } for ( var i = 0 ; i < Query . length ; i ++ ) { if ( Query [ i ] [ 0 ] == 1 ) { document . write ( A [ ( Query [ i ] [ 1 ] ) - 1 ] + " " ) ; } else { document . write ( A [ ( Query [ i ] [ 1 ] ) - 1 ] - A [ ( Query [ i ] [ 0 ] ) - 2 ] + " " ) ; } } } var S = " " ; var Query = [ ] ; Query . push ( [ 2 , 4 ] ) ; Query . push ( [ 1 , 3 ] ) ; Range_sum_query ( S , Query ) ;
Generate all possible permutations of a Number divisible by N | Function to Swap two characters ; Function to generate all permutations and print the ones that are divisible by the N ; Convert String to integer ; Check for divisibility and print it ; Print all the permutations ; Swap characters ; Permute remaining characters ; Revoke the swaps ; Driver Code
function swap_ ( a , l , i ) { let temp ; temp = a [ l ] ; a [ l ] = a [ i ] ; a [ i ] = temp ; } function permute ( str , l , r , n ) { let i ; if ( l == r ) { let j = parseInt ( ( str ) . join ( " " ) ) ; if ( j % n == 0 ) document . write ( ( str ) . join ( " " ) + " " ) ; return ; } for ( i = l ; i < r ; i ++ ) { swap_ ( str , l , i ) ; permute ( str , l + 1 , r , n ) ; swap_ ( str , l , i ) ; } } let str = " " ; let n = 5 ; let len = str . length ; if ( len > 0 ) permute ( str . split ( " " ) , 0 , len , n ) ;
Check if binary representations of 0 to N are present as substrings in given binary string | Function to convert decimal to binary representation ; Iterate over all bits of N ; If bit is 1 ; Return binary representation ; Function to check if binary conversion of numbers from N to 1 exists in the string as a substring or not ; To store the count of number exists as a substring ; Traverse from N to 1 ; If current number is not present in map ; Store current number ; Find binary of t ; If the string s is a substring of str ; Mark t as true ; Increment the count ; Update for t / 2 ; Special judgment '0' ; If the count is N + 1 , return " yes " ; Given String ; Given Number ; Function Call
function decimalToBinary ( N ) { var ans = " " ; while ( N > 0 ) { if ( N % 2 == 1 ) { ans = ' ' + ans ; } else { ans = ' ' + ans ; } N = parseInt ( N / 2 ) ; } return ans ; } function checkBinaryString ( str , N ) { var map = Array ( N + 10 ) . fill ( 0 ) , cnt = 0 ; for ( var i = N ; i > 0 ; i -- ) { if ( ! map [ i ] ) { var t = i ; var s = decimalToBinary ( t ) ; if ( str . includes ( s ) ) { while ( t > 0 && map [ t ] == 0 ) { map [ t ] = 1 ; cnt ++ ; t >>= 1 ; } } } } for ( var i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) { cnt ++ ; break ; } } if ( cnt == N + 1 ) return " " ; else return " " ; } var str = " " ; var N = 3 ; document . write ( checkBinaryString ( str , N ) ) ;
Find the word with most anagrams in a given sentence | Function to find the word with maximum number of anagrams ; Primes assigned to 26 alphabets ; Stores the product and word mappings ; Stores the frequencies of products ; Calculate the product of primes assigned ; If product already exists ; Otherwise ; Fetch the most frequent product ; Return a string with that product ; Driver Code
function largestAnagramGrp ( arr ) { var prime = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 , 101 , ] ; var max = - 1 ; var maxpdt = - 1 ; var W = { } ; var P = { } ; for ( const temp of arr ) { var c = temp . split ( " " ) ; var pdt = 1 ; for ( const t of c ) { pdt *= prime [ t . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ; } if ( P . hasOwnProperty ( pdt ) ) { P [ pdt ] = P [ pdt ] + 1 ; } else { W [ pdt ] = temp ; P [ pdt ] = 1 ; } } for ( const [ key , value ] of Object . entries ( P ) ) { if ( max < value ) { max = value ; maxpdt = key ; } } return W [ maxpdt ] ; } var S = " " + " " ; var arr = S . split ( " " ) ; document . write ( largestAnagramGrp ( arr ) ) ;
Replace every vowels with lexicographically next vowel in a String | Function to replace every vowel with next vowel lexicographically ; Storing the vowels in the map with custom numbers showing their index ; Iterate over the string ; If the current character is a vowel Find the index in Hash and Replace it with next vowel from Hash ; Driver function
function print_next_vovel_string ( st ) { var m = { } ; m [ " " ] = 0 ; m [ " " ] = 1 ; m [ " " ] = 2 ; m [ " " ] = 3 ; m [ " " ] = 4 ; var arr = [ " " , " " , " " , " " , " " ] ; var N = st . length ; for ( let i = 0 ; i < N ; i ++ ) { var c = st [ i ] ; if ( c === " " c === " " c === " " c === " " c === " " ) { index = m [ st [ i ] ] + 1 ; newindex = index % 5 ; st = st . replace ( st [ i ] , arr [ newindex ] ) ; } } return st ; } var st = " " ; document . write ( print_next_vovel_string ( st ) ) ;
Check if string is palindrome after removing all consecutive duplicates | Function to check if a String is palindrome or not ; Length of the String ; Check if its a palindrome ; If the palindromic condition is not met ; Return true as str is palindromic ; Function to check if String str is palindromic after removing every consecutive characters from the str ; Length of the String str ; Create an empty compressed String ; The first character will always be included in the readonly String ; Check all the characters of the String ; If the current character is not same as its previous one , then insert it in the readonly String ; Check if the compressed String is a palindrome ; Given String ; Function call
function isPalindrome ( str ) { let len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { if ( str [ i ] != str [ len - i - 1 ] ) return false ; } return true ; } function isCompressablePalindrome ( str ) { let len = str . length ; let compressed = " " ; compressed = str [ 0 ] ; for ( let i = 1 ; i < len ; i ++ ) { if ( str [ i ] != str [ i - 1 ] ) compressed += str [ i ] ; } return isPalindrome ( compressed ) ; } let str = " " ; if ( isCompressablePalindrome ( str ) ) document . write ( " " + " " ) ; else document . write ( " " ) ;