dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function smallestFreq ( S1 , S2 ) { let banned = new Map ( ) ; for ( let i = 0 ; i < S2 . length ; i ++ ) { let s = " " ; while ( i < S2 . length && S2 [ i ] != ' ' ) s += S2 [ i ++ ] ; banned . set ( s , banned [ s ] == null ? 1 : banned . get ( s ) + 1 ) ; } let result = new Map ( ) ; let ans = " " ; let freq = 0 ; for ( let i = 0 ; i < S1 . length ; i ++ ) { let s = " " ; while ( i < S1 . length && S1 [ i ] != ' ' ) s += S1 [ i ++ ] ; if ( banned . get ( s ) == null ) { result . set ( s , result . get ( s ) == null ? 1 : result . get ( s ) + 1 ) ; if ( result . get ( s ) > freq || ( result . get ( s ) == freq && s < ( ans ) ) ) { ans = s ; freq = result . get ( s ) ; } } } return ans ; } let S1 = " " ; let S2 = " " ; document . write ( smallestFreq ( S1 , S2 ) ) ;

Index/key variables: i, s
Accumulator variables: i, s
Iterator variables: i
Javascript program:
function isSubstring ( s1 , s2 ) { var M = s1 . length ; var N = s2 . length ; for ( var i = 0 ; i <= N - M ; i ++ ) { var j ; for ( j = 0 ; j < M ; j ++ ) if ( s2 [ i + j ] != s1 [ j ] ) break ; if ( j == M ) return i ; } return - 1 ; } var s1 = " " ; var s2 = " " ; var res = isSubstring ( s1 , s2 ) ; if ( res == - 1 ) document . write ( " " ) ; else document . write ( " " + res ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function KMP ( m , n , str2 , str1 ) { var pos = 0 , len = 0 ; var p = Array ( m + 1 ) . fill ( 0 ) ; var k = 0 ; p [ 1 ] = 0 ; for ( var i = 2 ; i <= n ; i ++ ) { while ( k > 0 && str1 [ k ] != str1 [ i - 1 ] ) k = p [ k ] ; if ( str1 [ k ] == str1 [ i - 1 ] ) ++ k ; p [ i ] = k ; } for ( var j = 0 , i = 0 ; i < m ; i ++ ) { while ( j > 0 && str1 [ j ] != str2 [ i ] ) j = p [ j ] ; if ( str1 [ j ] == str2 [ i ] ) j ++ ; if ( j > len ) { len = j ; pos = i - j + 1 ; } } document . write ( " " + pos + " " ) ; document . write ( " " + str1 . substr ( 0 , len ) ) ; } var str1 = " " ; var str2 = " " ; var n = str1 . length ; str2 = str2 + str2 ; KMP ( 2 * n , n , str2 , str1 ) ;

Index/key variables: i, j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function patternCount ( str ) { var last = str . charAt ( 0 ) ; var i = 1 , counter = 0 ; while ( i < str . length ) { if ( str . charAt ( i ) == ' ' && last == ' ' ) { while ( str . charAt ( i ) == ' ' ) i ++ ; if ( str . charAt ( i ) == ' ' ) counter ++ ; } last = str . charAt ( i ) ; i ++ ; } return counter ; } var str = " " ; document . write ( patternCount ( str ) ) ;

Accumulator variables: counter, i
Javascript program:
function maxPrefix ( s , t ) { let count = 0 ; for ( let i = 0 ; i < t . length ; i ++ ) { if ( count == s . length ) break ; if ( t [ i ] == s [ count ] ) count ++ ; } return count ; } let S = " " ; let T = " " ; document . write ( maxPrefix ( S , T ) ) ;

Index/key variables: count, i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function translate ( str ) { for ( let i = 1 ; i < str . length ; i ++ ) { if ( str [ i - 1 ] == ' ' && str [ i ] == ' ' ) { str [ i - 1 ] = ' ' ; let j ; for ( j = i ; j < str . length - 1 ; j ++ ) str [ j ] = str [ j + 1 ] ; str [ j ] = ' ' ; } } return ; } let st = " " ; let str = st . split ( " " ) ; translate ( str ) ; document . write ( " " ) ; document . write ( str . join ( " " ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let ROW = 3 ; let COL = 5 ; function isvalid ( row , col , prevRow , prevCol ) { return ( row >= 0 ) && ( row < ROW ) && ( col >= 0 ) && ( col < COL ) && ! ( row == prevRow && col == prevCol ) ; } let rowNum = [ - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 ] ; let colNum = [ - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 ] ; function DFS ( mat , row , col , prevRow , prevCol , word , path , index , n ) { if ( index > n mat [ row ] [ col ] != word [ index ] ) return ; path += ( word [ index ] ) + " " + ( row ) . toString ( ) + " " + ( col ) . toString ( ) + " " ; if ( index == n ) { document . write ( path + " " ) ; return ; } for ( let k = 0 ; k < 8 ; ++ k ) if ( isvalid ( row + rowNum [ k ] , col + colNum [ k ] , prevRow , prevCol ) ) DFS ( mat , row + rowNum [ k ] , col + colNum [ k ] , row , col , word , path , index + 1 , n ) ; } function findWords ( mat , word , n ) { for ( let i = 0 ; i < ROW ; ++ i ) for ( let j = 0 ; j < COL ; ++ j ) if ( mat [ i ] [ j ] == word [ 0 ] ) DFS ( mat , i , j , - 1 , - 1 , word , " " , 0 , n ) ; } let mat = [ [ ' ' , ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' , ' ' ] ] ; let word = " " . split ( " " ) ; findWords ( mat , word , word . length - 1 ) ;

Index/key variables: col, i, index, j, k, row
Accumulator variables: path
Iterator variables: i, j, k
Javascript program:
const maxSize = 10 ; function randomHexInt ( N ) { let hexChar = [ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' ] ; for ( let i = 0 ; i < N ; i ++ ) { let len = Math . random ( ) * ( maxSize - 1 ) + 1 ; for ( let j = 0 ; j < len ; j ++ ) { document . write ( hexChar [ Math . floor ( Math . random ( ) * ( 16 ) ) ] ) ; } document . write ( " " ) } } let N = 3 ; randomHexInt ( N ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function checkEqualArrays ( arr , brr , N ) { let siz = arr [ 0 ] . length ; for ( let i = 0 ; i < N ; i ++ ) { arr [ i ] = arr [ i ] . split ( " " ) . sort ( ) . join ( " " ) brr [ i ] = brr [ i ] . split ( " " ) . sort ( ) . join ( " " ) } arr . sort ( ) brr . sort ( ) for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != brr [ i ] ) { return false ; } } return true ; } let N = 2 ; let arr = [ " " , " " ] ; let brr = [ " " , " " ] ; let ans = checkEqualArrays ( arr , brr , N ) ; if ( ans ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let maxi = 0 ; let ans1 = " " ; function calculate ( ans ) { let dp = new Array ( 26 ) . fill ( 0 ) ; for ( let i = 0 ; i < ans . length ; ++ i ) { dp [ ans [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } for ( let i = 0 ; i < 26 ; ++ i ) { if ( dp [ i ] % 2 == 1 ) { return ; } } if ( maxi < ans . length ) { maxi = ans . length ; ans1 = ans ; } } function longestString ( arr , index , str ) { if ( index == arr . length ) { return ; } longestString ( arr , index + 1 , str ) ; str += arr [ index ] ; calculate ( str ) ; longestString ( arr , index + 1 , str ) ; } let A = [ " " , " " , " " , " " , " " ] ; longestString ( A , 0 , " " ) ; document . write ( ans1 + " " + ans1 . length ) ;

Index/key variables: i, index
Accumulator variables: str
Iterator variables: i
Javascript program:
function generateNumber ( number ) { let temp = 0 , adding_number = 0 ; let result = " " ; let len = number . length ; for ( let i = len - 1 ; i >= 0 ; i -- ) { let digit = parseInt ( number [ i ] ) ; if ( temp % 2 == 0 ) { adding_number += 1 ; digit += adding_number ; if ( digit >= 10 ) { digit %= 9 ; if ( digit == 0 ) digit = 9 ; } } result = ( digit ) . toString ( ) + result ; temp += 1 ; } return result ; } let S = " " ; document . write ( generateNumber ( S ) ) ;

Index/key variables: i
Accumulator variables: adding_number, digit, i, temp
Iterator variables: i
Javascript program:
function findTheSum ( str ) { let alpha = [ ] ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( ( str [ i ] . charCodeAt ( 0 ) >= " " . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) || ( str [ i ] . charCodeAt ( 0 ) >= " " . charCodeAt ( 0 ) && str [ i ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) ) alpha . push ( str [ i ] ) ; } let score = 0 , n = 0 ; for ( let i = 0 ; i < alpha . length ; i ++ ) { if ( alpha [ i ] . charCodeAt ( 0 ) >= " " . charCodeAt ( 0 ) && alpha [ i ] . charCodeAt ( 0 ) <= " " . charCodeAt ( 0 ) ) score += alpha [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) + 1 ; else score += alpha [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) + 1 ; } while ( score > 0 n > 9 ) { if ( score == 0 ) { score = n ; n = 0 ; } n += score % 10 ; score = Math . floor ( score / 10 ) ; } return n ; } let S = " " ; document . write ( findTheSum ( S ) ) ;

Index/key variables: i
Accumulator variables: i, n, score
Iterator variables: i
Javascript program:
function findK ( s , c ) { let n = s . length ; let diff ; let max = 0 ; let prev = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == c ) { diff = i - prev ; prev = i ; if ( diff > max ) { max = diff ; } } } if ( max == 0 ) return - 1 ; return max ; } let S = " " ; let ch = " " ; document . write ( findK ( S , ch ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSubsequence ( S , N , K ) { let C = 0 , C1 = 0 , C0 = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == " " ) C1 ++ ; else if ( S [ i ] == " " ) C0 ++ ; } let B1 = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == " " ) B1 ++ ; else if ( S [ i ] == " " ) C = C + ( C1 - B1 ) ; } let ans = C * K ; ans += C1 * C0 * ( ( K * ( K - 1 ) ) / 2 ) ; return ans ; } let S = " " ; let K = 2 ; let N = S . length ; document . write ( countSubsequence ( S , N , K ) ) ;

Index/key variables: i
Accumulator variables: B1, C0, C1, ans, i
Iterator variables: i
Javascript program:
const convertString = ( S , a , b ) => { let N = S . length ; for ( let i = 0 ; i < parseInt ( N / 2 ) ; ++ i ) { if ( S [ i ] == ' ' && S [ N - i - 1 ] != ' ' ) { S [ i ] = S [ N - i - 1 ] ; } else if ( S [ i ] != ' ' && S [ N - i - 1 ] == ' ' ) { S [ N - i - 1 ] = S [ i ] ; } } let cnt_0 = 0 ; for ( let i = 0 ; i < N ; ++ i ) { if ( S [ i ] == ' ' ) cnt_0 ++ ; } a = a - cnt_0 ; let cnt_1 = 0 ; for ( let i = 0 ; i < N ; ++ i ) { if ( S [ i ] == ' ' ) cnt_1 ++ ; } b = b - cnt_1 ; for ( let i = 0 ; i < parseInt ( N / 2 ) ; ++ i ) { if ( S [ i ] == ' ' && S [ N - i - 1 ] == ' ' ) { if ( a > b ) { S [ i ] = S [ N - i - 1 ] = ' ' ; a -= 2 ; } else { S [ i ] = S [ N - i - 1 ] = ' ' ; b -= 2 ; } } } if ( S [ parseInt ( N / 2 ) ] == ' ' ) { if ( a > b ) { S [ parseInt ( N / 2 ) ] = ' ' ; a -- ; } else { S [ parseInt ( N / 2 ) ] = ' ' ; b -- ; } } if ( a == 0 && b == 0 ) { return S ; } else { return " " ; } } let S = " " ; S = S . split ( ' ' ) ; let a = 4 , b = 4 ; document . write ( convertString ( S , a , b ) . join ( ' ' ) ) ;

Index/key variables: i
Accumulator variables: a, b, cnt_0, cnt_1
Iterator variables: i
Javascript program:
function minSwaps ( s ) { let ones = 0 , zeros = 0 ; let N = s . length ; for ( let i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ' ) ones ++ ; else zeros ++ ; } if ( ( N % 2 == 0 && ones != zeros ) || ( N % 2 == 1 && Math . abs ( ones - zeros ) != 1 ) ) { return - 1 ; } let ans_1 = 0 ; let j = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { ans_1 += Math . abs ( j - i ) ; j += 2 ; } } let ans_0 = 0 ; let k = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { ans_0 += Math . abs ( k - i ) ; k += 2 ; } } if ( N % 2 == 0 ) return Math . min ( ans_1 , ans_0 ) ; else { if ( ones > zeros ) return ans_1 ; else return ans_0 ; } } let S = " " ; document . write ( minSwaps ( S ) ) ;

Accumulator variables: ans_0, ans_1, i, j, k, ones, zeros
Iterator variables: i
Javascript program:
const TotalPossibleJumps = ( N ) => { if ( ( N - 1 ) == 0 ) { let newvec = [ ] ; newvec . push ( " " ) ; return newvec ; } else { if ( N < 0 ) { let newvec = [ ] ; return newvec ; } } let jump1 = TotalPossibleJumps ( N - 1 ) ; let jump2 = TotalPossibleJumps ( N - 2 ) ; let totaljumps = [ ] ; for ( let s in jump1 ) { totaljumps . push ( " " + jump1 [ s ] ) ; } for ( let s in jump2 ) { totaljumps . push ( " " + jump2 [ s ] ) ; } return totaljumps ; } let N = 3 ; let Ans = TotalPossibleJumps ( N ) ; for ( let it in Ans ) document . write ( ` ${ Ans [ it ] } ` ) ;

Index/key variables: it, s
Iterator variables: it, s
Javascript program:
function findString ( arr , N ) { let ans = " " ; for ( let i = 0 ; i < N ; i ++ ) { ans += arr [ i ] [ i ] == ' ' ? ' ' : ' ' ; } return ans ; } let arr = [ " " , " " , " " ] ; let N = arr . length ; document . write ( findString ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function commonSubstring ( s ) { let n = s . length ; let i = 0 ; let j = n - 1 ; let ans = " " ; while ( j >= 0 ) { if ( s [ i ] == s [ j ] ) { ans += s [ i ] ; i ++ ; j -- ; } else { break ; } } if ( ans . length == 0 ) document . write ( " " ) ; else { document . write ( " " + " " + ans ) ; } } let S = " " ; commonSubstring ( S ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Javascript program:
function findMinimumSubsequence ( S ) { let flag = false ; for ( let j = 0 ; j < S . length ; j ++ ) { if ( S [ j ] != ' ' && S [ j ] != ' ' && S [ j ] != ' ' && S [ j ] != ' ' ) { document . write ( 1 ) ; flag = true ; break ; } } if ( flag == false ) { for ( let j = 0 ; j < S . length ; j ++ ) { for ( let j1 = j + 1 ; j1 < S . length ; j1 ++ ) { let dummy = S [ j ] + S [ j1 ] ; if ( dummy != " " && dummy != " " && dummy != " " && dummy != " " ) { document . write ( 2 ) ; } if ( flag == true ) break ; else flag = true ; } if ( flag == true ) break ; } } if ( flag == false ) { if ( S . length >= 3 ) { document . write ( 3 ) ; } else { document . write ( - 1 ) ; } } } let S = " " ; findMinimumSubsequence ( S ) ;

Index/key variables: j, j1
Accumulator variables: j, j1
Iterator variables: j, j1
Boolean variables: flag
Javascript program:
function operations ( s ) { let ans = 0 ; let vowels = 0 , consonants = 0 ; let max_vowels = Number . MIN_VALUE ; let max_consonants = Number . MIN_VALUE ; let freq_consonants = new Map ( ) ; let freq_vowels = new Map ( ) ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s . charAt ( i ) == ' ' || s . charAt ( i ) == ' ' || s . charAt ( i ) == ' ' || s . charAt ( i ) == ' ' || s . charAt ( i ) == ' ' ) { vowels += 1 ; if ( freq_vowels . has ( s . charAt ( i ) ) ) { freq_vowels . set ( s . charAt ( i ) , freq_vowels . get ( s . charAt ( i ) ) + 1 ) } else { freq_vowels . set ( s . charAt ( i ) , 1 ) ; } } else { consonants += 1 ; if ( freq_consonants . has ( s . charAt ( i ) ) ) { freq_consonants . set ( s . charAt ( i ) , freq_consonants . get ( s . charAt ( i ) ) + 1 ) } else { freq_consonants . set ( s . charAt ( i ) , 1 ) ; } } } for ( let [ key , value ] of freq_consonants ) { max_consonants = Math . max ( max_consonants , value ) ; } for ( let [ key1 , value1 ] of freq_vowels ) { max_vowels = Math . max ( max_vowels , value1 ) ; } ans = Math . min ( ( 2 * ( vowels - max_vowels ) + consonants ) , ( 2 * ( consonants - max_vowels ) + consonants ) ) ; return ans ; } let S = " " ; document . write ( operations ( S ) ) ;

Accumulator variables: consonants, i, vowels
Iterator variables: i
Javascript program:
var dp = new Array ( 505 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 505 ) . fill ( - 1 ) ; } var choose = new Array ( 505 ) ; for ( var i = 0 ; i < choose . length ; i ++ ) { choose [ i ] = new Array ( 505 ) . fill ( 0 ) ; } function calc ( l , r , s ) { if ( Math . abs ( r - l ) % 2 == 0 ) { return 0 ; } if ( l > r ) { return dp [ l ] [ r ] = 1 ; } if ( dp [ l ] [ r ] != - 1 ) { return dp [ l ] [ r ] ; } if ( ( r - l ) == 1 ) { if ( s [ l ] == s [ r ] ) { dp [ l ] [ r ] = 1 ; } else { dp [ l ] [ r ] = 0 ; } return dp [ l ] [ r ] ; } let ans = 0 ; for ( let k = l + 1 ; k <= r ; k += 2 ) { let temp = 1 ; if ( s [ l ] == s [ k ] ) { temp = calc ( l + 1 , k - 1 , s ) * calc ( k + 1 , r , s ) * choose [ Math . floor ( ( r - l + 1 ) / 2 ) ] [ Math . floor ( ( r - k ) / 2 ) ] ; ans += temp ; } } return dp [ l ] [ r ] = ans ; } function waysToClearString ( S ) { let n = S . length ; choose [ 0 ] [ 0 ] = 1 ; for ( let i = 1 ; i <= Math . floor ( n / 2 ) ; ++ i ) { choose [ i ] [ 0 ] = 1 ; for ( let j = 1 ; j <= i ; ++ j ) { choose [ i ] [ j ] = ( choose [ i - 1 ] [ j ] + choose [ i - 1 ] [ j - 1 ] ) ; } } return calc ( 0 , n - 1 , S ) ; } let S = " " ; document . write ( waysToClearString ( S ) ) ;

Index/key variables: i, j, k, l, r
Accumulator variables: ans, i, k
Iterator variables: i, j, k
Javascript program:
function findSubsequence ( str ) { let n = str . length ; let res = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) res [ i ] = 0 ; for ( let pos = 0 ; pos <= 9 ; pos ++ ) { let lst1 = ' ' ; let flag = 1 ; let lst2 = String . fromCharCode ( pos + ' ' . charCodeAt ( 0 ) ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( lst2 . charCodeAt ( 0 ) <= str [ i ] . charCodeAt ( 0 ) ) { res [ i ] = ' ' ; lst2 = str [ i ] ; } else if ( lst1 . charCodeAt ( 0 ) <= str [ i ] . charCodeAt ( 0 ) ) { res [ i ] = ' ' ; lst1 = str [ i ] ; } else flag = 0 ; } if ( lst1 . charCodeAt ( 0 ) > pos + ' ' . charCodeAt ( 0 ) ) { flag = 0 ; } if ( flag ) { let S1 = " " ; let S2 = " " ; for ( let i = 0 ; i < n ; i ++ ) { if ( res [ i ] == ' ' ) { S1 += str [ i ] ; } else { S2 += str [ i ] ; } } document . write ( S1 + ' ' + S2 + ' ' ) ; return ; } } document . write ( " " ) ; } let S = " " ; findSubsequence ( S ) ; S = " " ; findSubsequence ( S ) ;

Index/key variables: i
Accumulator variables: S1, S2, i, pos
Iterator variables: i, pos
Javascript program:
var ans , s ; var K ; function getString ( curlen , N , prod ) { if ( curlen == N ) { K -- ; if ( K == 0 ) ans = s ; return ; } var ch ; var ok , t , i ; for ( ch = ' ' ; ch <= ' ' ; ch ++ ) { s += ch ; ok = 1 ; t = 1 ; for ( i = curlen ; i >= 0 && s . length > i ; i -- ) { t *= s . charAt ( i ) - 48 ; if ( prod [ t ] != 0 ) ok = 0 ; prod [ t ] ++ ; } if ( ok != 0 ) getString ( curlen + 1 , N , prod ) ; t = 1 ; for ( i = curlen ; i >= 0 && s . length > i ; i -- ) { t *= s . charAt ( i ) - 48 ; prod [ t ] -- ; } if ( s . length > 0 ) s = s . substring ( 0 , s . length - 1 ) ; } } function kthValidString ( N ) { if ( N > 10 ) { return " " ; } if ( N == 1 ) { if ( K > 10 ) { return " " ; } var s = " " ; K -- ; s += ( K + ' ' ) ; return s ; } var ans = " " ; var s = " " ; var prod = new Array ( 10005 ) ; getString ( 0 , N , prod ) ; return ans ; } var N = 3 ; var K = 4 ; document . write ( kthValidString ( N ) ) ;

Index/key variables: t
Accumulator variables: K, ch, i, s, t
Iterator variables: ch, i
Javascript program:
function BalancedStringBySwapping ( s ) { var unbalancedPair = 0 ; for ( var i = 0 ; i < s . length ; ++ i ) { if ( unbalancedPair > 0 && s [ i ] == ' ' ) { -- unbalancedPair ; } else if ( s [ i ] == ' ' ) { ++ unbalancedPair ; } } return ( unbalancedPair + 1 ) / 2 ; } var s = " " ; document . write ( BalancedStringBySwapping ( s ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function lengthNPalindrome ( N , K ) { var half = N / 2 ; if ( N & 1 ) { half += 1 ; } var ans = 1 ; var i ; for ( i = 1 ; i <= half ; i ++ ) { ans *= K ; K -- ; } return ans ; } function palindromicStrings ( N , K ) { if ( N == 1 ) { return K ; } if ( N == 2 ) { return 2 * K ; } ans = 0 ; ans += ( 2 * K ) ; for ( i = 3 ; i <= N ; i ++ ) { ans += lengthNPalindrome ( i , K ) ; } return ans ; } var N = 4 , K = 3 ; document . write ( palindromicStrings ( N , K ) ) ;

Accumulator variables: K, ans, half, i
Iterator variables: i
Javascript program:
function LCS ( S , N , T , M , dp ) { if ( N == 0 M == 0 ) return 0 ; if ( dp [ N ] [ M ] != 0 ) return dp [ N ] [ M ] ; if ( S . charAt ( N - 1 ) == T . charAt ( M - 1 ) ) { return dp [ N ] [ M ] = 1 + LCS ( S , N - 1 , T , M - 1 , dp ) ; } return dp [ N ] [ M ] = Math . max ( LCS ( S , N - 1 , T , M , dp ) , LCS ( S , N , T , M - 1 , dp ) ) ; } function minimumCharacter ( S ) { var T = " " ; var N = S . length , M = T . length ; var dp = Array ( N + 1 ) . fill ( 0 ) . map ( x => Array ( M + 1 ) . fill ( 0 ) ) ; return ( 26 - LCS ( S , N , T , M , dp ) ) ; } var S = " " ; document . write ( minimumCharacter ( S ) ) ;

Index/key variables: M, N
Javascript program:
function printMiddleString ( S , T , N ) { let a1 = new Array ( N + 1 ) ; for ( let i = 0 ; i < N ; i ++ ) { a1 [ i + 1 ] = S [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) + T [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; } for ( let i = N ; i >= 1 ; i -- ) { a1 [ i - 1 ] += a1 [ i ] / 26 ; a1 [ i ] %= 26 ; } for ( let i = 0 ; i <= N ; i ++ ) { if ( a1 [ i ] & 1 ) { if ( i + 1 <= N ) { a1 [ i + 1 ] += 26 ; } } a1 [ i ] = Math . floor ( a1 [ i ] / 2 ) ; } for ( let i = 1 ; i <= N ; i ++ ) { document . write ( String . fromCharCode ( a1 [ i ] + " " . charCodeAt ( 0 ) ) ) ; } return 0 ; } let N = 5 ; let S = " " ; let T = " " ; printMiddleString ( S , T , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function KthCharacter ( s , t , k ) { let f = 1 ; let ss = 2 ; let tmp = " " ; let len = tmp . length ; while ( len < k ) { let tf = f ; let ts = ss ; while ( tf -- != 0 ) { tmp += s ; } while ( ts -- != 0 ) { tmp += t ; } f += 2 ; ss += 2 ; len = tmp . length ; } let output = tmp [ k - 1 ] ; return output ; } let S1 = " " , S2 = " " ; let k = 4 ; let ans = KthCharacter ( S1 , S2 , k ) ; document . write ( ans ) ;

Accumulator variables: f, ss, tf, tmp, ts
Javascript program:
function KthCharacter ( s , t , k ) { var n = s . length ; var m = t . length ; var first = 1 ; var second = 2 ; var output = ' ' ; while ( k > 0 ) { if ( k > first * n ) { var x = first * n ; k = k - x ; first = first + 2 ; if ( k > second * m ) { var y = second * m ; k = k - y ; second = second + 2 ; } else { var ind = k % m ; ind -- ; if ( ind < 0 ) ind = m - 1 ; output = t . charAt ( parseInt ( ind ) ) ; break ; } } else { var ind = k % n ; ind -- ; if ( ind < 0 ) ind = n - 1 ; output = s . charAt ( parseInt ( ind ) ) ; break ; } } return output ; } var S1 = " " , S2 = " " ; var k = 4 ; var ans = KthCharacter ( S1 , S2 , k ) ; document . write ( ans ) ;

Accumulator variables: ind
Javascript program:
function modifyString ( S , K ) { let N = S . length ; for ( let i = 0 ; i < K ; i ++ ) { let M = new Map ( ) ; for ( let j = i ; j < N ; j += K ) { if ( M . has ( S [ j ] ) ) { M . set ( M . get ( S [ j ] ) , M . get ( S [ j ] ) + 1 ) ; } else { M . set ( S [ j ] , 1 ) ; } } if ( M . size > 2 ) { return " " ; } else if ( M . size == 1 ) { if ( M . has ( ' ' ) ) { for ( let j = i ; j < N ; j += K ) { S = S . replace ( S [ j ] , ' ' ) ; } } } else if ( M . size == 2 ) { let ch ; for ( let it of M . keys ( ) ) { if ( it != ' ' ) { ch = it ; } } for ( let j = i ; j < N ; j += K ) { S = S . replace ( S [ j ] , ch ) ; } } M . clear ( ) ; } return S ; } let S = " " ; let K = 2 ; document . write ( modifyString ( S , K ) ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, it, j
Javascript program:
function fact ( n ) { var ans = 1 ; for ( var i = 2 ; i <= n ; i ++ ) ans = ans * i ; return ans ; } function findComb ( N , M ) { var x = fact ( N + 1 ) var y = fact ( M ) return ( x * y ) } var N = 2 var M = 2 document . write ( findComb ( N , M ) )

Accumulator variables: i
Iterator variables: i
Javascript program:
function findRepitition ( a ) { if ( a . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) && a . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) ) { return a . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; } else if ( a <= ' ' && a >= ' ' ) { return a . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; } return 0 ; } function decodeString ( str ) { let output = " " ; for ( let i = 0 ; i < str . length ; i ++ ) { output += ( str [ i ] ) ; i += findRepitition ( str [ i ] ) ; } document . write ( " " + output + " " + " " ) ; } let str = " " ; decodeString ( str ) ;

Index/key variables: i
Accumulator variables: i, output
Iterator variables: i
Javascript program:
function canMadeEmpty ( s , n ) { let St = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) { if ( St . length >= 2 ) { let b = St [ St . length - 1 ] ; St . pop ( ) ; let a = St [ St . length - 1 ] ; St . pop ( ) ; if ( a != ' ' b != ' ' ) return " " ; } else return " " ; } else St . push ( s [ i ] ) ; } if ( St . length == 0 ) { return " " ; } else { return " " ; } } let S = " " ; let N = S . length ; document . write ( canMadeEmpty ( S , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i