dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function valid ( cnt ) { for ( var i = 0 ; i < 26 ; i ++ ) { if ( cnt [ i ] >= 2 ) return false ; } return true ; } function getGoodString ( ss , n ) { var s = ss . split ( " " ) ; if ( n < 26 ) return " " ; for ( var i = 25 ; i < n ; i ++ ) { var cnt = new Array ( 26 ) . fill ( 0 ) ; for ( var j = i ; j >= i - 25 ; j -- ) { cnt [ s [ j ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } if ( valid ( cnt ) ) { var cur = 0 ; while ( cnt [ cur ] > 0 ) cur ++ ; for ( var j = i - 25 ; j <= i ; j ++ ) { if ( s [ j ] === " " ) { s [ j ] = String . fromCharCode ( cur + " " . charCodeAt ( 0 ) ) ; cur ++ ; while ( cnt [ cur ] > 0 ) cur ++ ; } } return s . join ( " " ) ; } } return " " ; } var s = " " ; var n = s . length ; document . write ( getGoodString ( s , n ) ) ;

Index/key variables: cur, i, j
Accumulator variables: cur, i, j
Iterator variables: i, j
Javascript program:
function isVowel ( c ) { c = c . toLowerCase ( ) ; if ( c === " " c === " " c === " " c === " " c === " " ) { return true ; } return false ; } function swapRepeated ( str ) { for ( var i = 0 ; i < str . length - 1 ; i ++ ) { if ( ( isVowel ( str [ i ] ) && isVowel ( str [ i + 1 ] ) ) || ( ! isVowel ( str [ i ] ) && ! isVowel ( str [ i + 1 ] ) ) ) { var c = str [ i ] ; str [ i ] = str [ i + 1 ] ; str [ i + 1 ] = c ; } } return str . join ( " " ) ; } var str = " " ; document . write ( swapRepeated ( str . split ( " " ) ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function largestPalinSub ( s ) { let res = " " ; let mx = s [ 0 ] ; for ( let i = 1 ; i < s . length ; i ++ ) mx = String . fromCharCode ( Math . max ( mx . charCodeAt ( ) , s [ i ] . charCodeAt ( ) ) ) ; for ( let i = 0 ; i < s . length ; i ++ ) if ( s [ i ] == mx ) res += s [ i ] ; return res ; } let s = " " ; document . write ( largestPalinSub ( s ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function printString ( str , n ) { let ones = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( str [ i ] == ' ' ) ones ++ ; let used = false ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ' && ! used ) { used = true ; for ( let j = 0 ; j < ones ; j ++ ) document . write ( " " ) ; } if ( str [ i ] != ' ' ) document . write ( str [ i ] ) ; } if ( ! used ) for ( let j = 0 ; j < ones ; j ++ ) document . write ( " " ) ; } let str = " " ; let n = str . length ; printString ( str . split ( ' ' ) , n ) ;

Index/key variables: i
Accumulator variables: i, j, ones
Iterator variables: i, j
Boolean variables: used
Javascript program:
function findPermutation ( str , k ) { var has = new Array ( 26 ) ; for ( var i = 0 ; i < 26 ; i ++ ) has [ i ] = false ; var cnt = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) { if ( ! has [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ) { cnt ++ ; has [ str [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = true ; } } var ans = 1 ; for ( var i = 2 ; i <= cnt ; i ++ ) ans *= i ; for ( var i = cnt - k ; i > 1 ; i -- ) ans /= i ; return ans ; } var str = " " ; var k = 4 ; document . write ( findPermutation ( str , k ) ) ;

Index/key variables: i
Accumulator variables: ans, cnt, i
Iterator variables: i
Javascript program:
function product ( x ) { let prod = 1 ; while ( x > 0 ) { prod *= ( x % 10 ) ; x = parseInt ( x / 10 , 10 ) ; } return prod ; } function findNumber ( l , r ) { let b = r . toString ( ) ; let ans = r ; for ( let i = 0 ; i < b . length ; i ++ ) { if ( b [ i ] == ' ' ) continue ; let curr = b . split ( ' ' ) ; curr [ i ] = String . fromCharCode ( ( ( curr [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) - 1 ) + ' ' . charCodeAt ( ) ) ; for ( let j = i + 1 ; j < curr . length ; j ++ ) curr [ j ] = ' ' ; let num = 0 ; for ( let j = 0 ; j < curr . length ; j ++ ) num = num * 10 + ( curr [ j ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; if ( num >= l && product ( ans ) < product ( num ) ) ans = num ; } return ans ; } let l = 1 , r = 10 ; document . write ( findNumber ( l , r ) + " " ) ; l = 51 ; r = 62 ; document . write ( findNumber ( l , r ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, prod
Iterator variables: i, j
Javascript program:
function printExpansion ( str ) { var size = 0 ; for ( var i = str . length - 1 ; i >= 0 ; i -- ) { var subStr = str . substring ( i , i + ++ size ) ; document . write ( subStr ) ; } } var str = " " ; printExpansion ( str ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function constructBinString ( a , b , x ) { let d , i ; d = parseInt ( x / 2 , 10 ) ; if ( x % 2 == 0 && parseInt ( x / 2 , 10 ) != a ) { d -- ; document . write ( " " ) ; a -- ; } for ( i = 0 ; i < d ; i ++ ) document . write ( " " ) ; a = a - d ; b = b - d ; for ( i = 0 ; i < b ; i ++ ) { document . write ( " " ) ; } for ( i = 0 ; i < a ; i ++ ) { document . write ( " " ) ; } } let a = 4 , b = 3 , x = 2 ; constructBinString ( a , b , x ) ;

Accumulator variables: a, d, i
Iterator variables: i
Javascript program:
function matchPattern ( s ) { let count = 0 ; let n = s . length ; let i = 0 ; while ( i < n ) { while ( i < n && s [ i ] == ' ' ) { count ++ ; i ++ ; } while ( i < n && s [ i ] == ' ' ) { count -- ; i ++ ; } if ( count != 0 ) return false ; } return true ; } let s = " " ; if ( matchPattern ( s ) == true ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: count, i
Javascript program:
function maximum_one ( s , n ) { var cnt_one = 0 ; var max_cnt = 0 , temp = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) { cnt_one ++ ; temp ++ ; } else { max_cnt = Math . max ( temp , max_cnt ) ; temp = 0 ; } } max_cnt = Math . max ( max_cnt , temp ) ; var left = Array ( n ) ; var right = Array ( n ) ; if ( s [ 0 ] == ' ' ) left [ 0 ] = 1 ; else left [ 0 ] = 0 ; if ( s [ n - 1 ] == ' ' ) right [ n - 1 ] = 1 ; else right [ n - 1 ] = 0 ; for ( var i = 1 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) left [ i ] = left [ i - 1 ] + 1 ; else left [ i ] = 0 ; } for ( var i = n - 2 ; i >= 0 ; i -- ) { if ( s [ i ] == ' ' ) right [ i ] = right [ i + 1 ] + 1 ; else right [ i ] = 0 ; } for ( var i = 1 ; i < n - 1 ; i ++ ) { if ( s [ i ] == ' ' ) { var sum = left [ i - 1 ] + right [ i + 1 ] ; if ( sum < cnt_one ) max_cnt = Math . max ( max_cnt , sum + 1 ) ; else max_cnt = Math . max ( max_cnt , sum ) ; } } return max_cnt ; } var s = " " ; document . write ( maximum_one ( s , s . length ) ) ;

Index/key variables: i
Accumulator variables: cnt_one, i, temp
Iterator variables: i
Javascript program:
function MaxFreq ( str ) { let n = str . length ; let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { let s = " " ; for ( let j = i ; j < n ; j ++ ) { s += str [ j ] ; if ( mp . has ( s ) ) { mp . set ( s , mp . get ( s ) + 1 ) ; } else { mp . set ( s , 1 ) ; } } } let maxi = 0 ; let s = " " ; for ( let [ key , value ] of mp . entries ( ) ) { if ( value > maxi ) { maxi = value ; s = key ; } else if ( value == maxi ) { let ss = key ; if ( ss . length > s . length ) s = ss ; } } return s ; } let str = " " ; document . write ( MaxFreq ( str ) ) ;

Index/key variables: j
Accumulator variables: i, j, s
Iterator variables: i, j
Javascript program:
function maxFreq ( s , a , b ) { var fre = new Array ( 10 ) . fill ( 0 ) ; var n = s . length ; if ( a > b ) { var temp = a ; a = b ; b = temp ; } for ( var i = 0 ; i < n ; i ++ ) fre [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; if ( fre [ a ] === 0 && fre [ b ] === 0 ) return - 1 ; else if ( fre [ a ] >= fre [ b ] ) return a ; else return b ; } var a = 4 , b = 7 ; var s = " " ; document . write ( maxFreq ( s , a , b ) ) ;

Index/key variables: a, b, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function convert ( n , a , b ) { let l = new Array ( n ) ; let i ; for ( i = 0 ; i < n ; i ++ ) l [ i ] = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) l [ i ] = 1 ; } let cc = 0 ; let vl = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( l [ i ] == 0 ) { if ( vl != 0 ) cc += 1 ; vl = 0 ; } else vl += 1 ; } if ( vl != 0 ) cc += 1 ; document . write ( cc + " " ) ; } let a = " " ; let b = " " ; let n = a . length ; convert ( n , a , b ) ;

Index/key variables: i
Accumulator variables: cc, i, vl
Iterator variables: i
Javascript program:
function StringMatch ( s ) { var lo = 0 , hi = s . length , len = s . length ; var ans = [ ] ; for ( var x = 0 ; x < len ; x ++ ) { if ( s [ x ] == ' ' ) { ans . push ( lo ) ; lo += 1 ; } else { ans . push ( hi ) ; hi -= 1 ; } } ans . push ( lo ) ; document . write ( " " ) ; for ( var i = 0 ; i < ans . length ; i ++ ) { document . write ( ans [ i ] ) ; if ( i != ans . length - 1 ) document . write ( " " ) ; } document . write ( " " ) ; } var S = " " ; StringMatch ( S ) ;

Index/key variables: i, x
Accumulator variables: hi, i, lo, x
Iterator variables: i, x
Javascript program:
function countWays ( s1 , s2 , n ) { var a , b , c , d ; a = b = c = d = 0 ; var result = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( s2 . charAt ( i ) == ' ' ) { if ( s1 . charAt ( i ) == ' ' ) { c ++ ; } else { d ++ ; } } else { if ( s1 . charAt ( i ) == ' ' ) { a ++ ; } else { b ++ ; } } } result = a * d + b * c + c * d ; return result ; } var n = 5 ; var s1 = " " ; var s2 = " " ; document . write ( countWays ( s1 , s2 , n ) ) ;

Accumulator variables: a, b, c, d, i
Iterator variables: i
Javascript program:
function returnWinner ( s , l ) { let freq = new Array ( 26 ) ; freq . fill ( 0 ) ; for ( let i = 0 ; i < l ; i ++ ) { freq [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; } let cnt = 0 ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] % 2 != 0 ) cnt ++ ; } if ( ( cnt == 0 ) || ( cnt & 1 ) == 1 ) return 1 ; else return 2 ; } let s = " " ; let l = s . length ; let winner = returnWinner ( s , l ) ; document . write ( " " + winner ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function maxProductSum ( str , m ) { let n = str . length ; let maxProd = Number . MIN_VALUE , maxSum = Number . MIN_VALUE ; for ( let i = 0 ; i <= n - m ; i ++ ) { let product = 1 , sum = 0 ; for ( let j = i ; j < m + i ; j ++ ) { product = product * ( str [ j ] - ' ' ) ; sum = sum + ( str [ j ] - ' ' ) ; } maxProd = Math . max ( maxProd , product ) ; maxSum = Math . max ( maxSum , sum ) ; } document . write ( " " + maxProd + " " ) ; document . write ( " " + maxSum ) ; } let str = " " ; let m = 3 ; maxProductSum ( str , m ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isVowel ( ch ) { if ( ch !== " " && ch !== " " && ch !== " " && ch !== " " && ch !== " " ) return false ; return true ; } function replacingConsonants ( s ) { for ( var i = 0 ; i < s . length ; i ++ ) { if ( isVowel ( s [ i ] ) ) continue ; else { if ( s [ i ] > " " && s [ i ] < " " ) { if ( Math . abs ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) > Math . abs ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) ) s = s . substring ( 0 , i ) + " " + s . substring ( i + 1 ) ; else s = s . substring ( 0 , i ) + " " + s . substring ( i + 1 ) ; } else if ( s [ i ] > " " && s [ i ] < " " ) { if ( Math . abs ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) > Math . abs ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) ) s = s . substring ( 0 , i ) + " " + s . substring ( i + 1 ) ; else s = s . substring ( 0 , i ) + " " + s . substring ( i + 1 ) ; } else if ( s [ i ] > " " && s [ i ] < " " ) { if ( Math . abs ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) > Math . abs ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) ) s = s . substring ( 0 , i ) + " " + s . substring ( i + 1 ) ; else s = s . substring ( 0 , i ) + " " + s . substring ( i + 1 ) ; } else if ( s [ i ] > " " && s [ i ] < " " ) { if ( Math . abs ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) > Math . abs ( s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) ) s = s . substring ( 0 , i ) + " " + s . substring ( i + 1 ) ; else s = s . substring ( 0 , i ) + " " + s . substring ( i + 1 ) ; } else if ( s [ i ] > " " ) s = s . substring ( 0 , i ) + " " + s . substring ( i + 1 ) ; } } return s ; } var s = " " ; document . write ( replacingConsonants ( s ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxLength ( s , n ) { var right = 0 , left = 0 ; var coun = 0 , max_length = Number . MIN_VALUE ; s = s + ' ' ; for ( var i = 0 ; i <= n ; i ++ ) { if ( s [ i ] == ' ' ) coun ++ ; else { if ( coun > max_length ) { right = 0 ; left = 0 ; if ( s [ i ] == ' ' ) right = 1 ; if ( ( ( i - coun ) > 0 ) && ( s [ i - coun - 1 ] == ' ' ) ) left = 1 ; coun = Math . ceil ( coun / ( right + left ) ) ; max_length = Math . max ( max_length , coun ) ; } coun = 0 ; } } return max_length ; } var s = " " ; var n = s . length ; document . write ( maxLength ( s , n ) ) ;

Index/key variables: i
Accumulator variables: coun, i
Iterator variables: i
Javascript program:
function printLargestString ( s , l , r ) { var freq = Array ( 26 ) . fill ( 0 ) ; l -- ; r -- ; for ( i = Math . min ( l , r ) ; i <= Math . max ( l , r ) ; i ++ ) { freq [ s . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ] ++ ; } var ans = " " ; for ( var i = 25 ; i >= 0 ; i -- ) { while ( freq [ i ] > 0 ) { ans += String . fromCharCode ( ' ' . charCodeAt ( 0 ) + i ) ; freq [ i ] -- ; } } return ans ; } var s = " " ; var l = 3 , r = 5 ; document . write ( printLargestString ( s , l , r ) ) ;

Index/key variables: i
Accumulator variables: ans, i, l, r
Iterator variables: i
Javascript program:
function arrange ( s ) { var cc = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) cc ++ ; } var a = Array ( s . length + 1 ) . fill ( 0 ) ; var qq = [ [ 2 , 3 ] , [ 5 , 5 ] ] ; var n = qq . length ; for ( var i = 0 ; i < n ; i ++ ) { var l = qq [ i ] [ 0 ] , r = qq [ i ] [ 1 ] ; l -- , r -- ; a [ l ] ++ ; a [ r + 1 ] -- ; } var len_a = a . length ; for ( var i = 1 ; i < len_a ; i ++ ) { a [ i ] += a [ i - 1 ] ; } var zz = Array ( s . length ) . fill ( 0 ) ; for ( var i = 0 ; i < len_a - 1 ; i ++ ) { if ( a [ i ] > 0 ) { if ( cc > 0 ) { zz [ i ] = 1 ; cc -- ; } else break ; } if ( cc == 0 ) break ; } if ( cc > 0 ) { for ( var i = 0 ; i < s . length ; i ++ ) { if ( zz [ i ] == 0 ) { zz [ i ] = 1 ; cc -- ; } if ( cc == 0 ) break ; } } for ( var i = 0 ; i < s . length ; i ++ ) document . write ( zz [ i ] ) ; document . write ( " " ) ; } var str = " " ; arrange ( str ) ;

Index/key variables: i, l
Accumulator variables: cc, i, l, r
Iterator variables: i
Javascript program:
function areVowelsInOrder ( s ) { var n = s . length ; var c = String . fromCharCode ( 64 ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) { if ( s [ i ] < c ) return false ; else { c = s [ i ] ; } } } return true ; } var s = " " ; if ( areVowelsInOrder ( s ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function newString ( s ) { let l = s . length ; let freq = new Array ( 26 ) ; freq . fill ( 0 ) ; for ( let i = 0 ; i < l ; i ++ ) { freq [ s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] += 1 ; } let ans = " " ; for ( let i = 0 ; i < 26 ; i ++ ) { for ( let j = 0 ; j < freq [ i ] ; j ++ ) { ans += String . fromCharCode ( 97 + i ) ; } } return ans ; } let s = " " ; document . write ( newString ( s ) ) ;

Index/key variables: i
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function Remainder ( str , R ) { var len = str . length ; var Num , Rem = 0 ; for ( var i = 0 ; i < len ; i ++ ) { Num = Rem * 10 + ( str [ i ] - ' ' ) ; Rem = Num % R ; } return Rem ; } var str = " " ; var R = 13 ; document . write ( Remainder ( str , R ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countWays ( a , n ) { let i , j ; let suff = new Array ( n ) ; if ( a [ n - 1 ] == 2 ) suff [ n - 1 ] = 1 ; for ( i = n - 2 ; i >= 0 ; i -- ) { if ( a [ i ] == 2 ) suff [ i ] = suff [ i + 1 ] + 1 ; else suff [ i ] = suff [ i + 1 ] ; } let ss = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 1 ) ss += suff [ i ] ; } for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { if ( a [ i ] == 1 && a [ j ] == 1 && suff [ j ] >= 2 ) { ss += ( suff [ j ] ) * ( suff [ j ] - 1 ) / 2 ; } } } for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { if ( a [ i ] == 1 && a [ j ] == 1 && ( suff [ i ] - suff [ j ] ) >= 1 && suff [ j ] >= 1 ) { ss += ( suff [ i ] - suff [ j ] ) * suff [ j ] ; } } } document . write ( ss ) ; } let a = [ 1 , 2 , 1 , 1 , 2 , 2 ] ; let n = 6 ; countWays ( a , n ) ;

Index/key variables: i, j
Accumulator variables: i, j, ss
Iterator variables: i, j
Javascript program:
function count_carry ( a , b ) { let carry = 0 ; let count = 0 ; let len_a = a . length , len_b = b . length ; while ( len_a != 0 len_b != 0 ) { let x = 0 , y = 0 ; if ( len_a > 0 ) { x = a [ len_a - 1 ] - ' ' ; len_a -- ; } if ( len_b > 0 ) { y = b [ len_b - 1 ] - ' ' ; len_b -- ; } let sum = x + y + carry ; if ( sum >= 10 ) { carry = 1 ; count ++ ; } else carry = 0 ; } return count ; } let a = " " , b = " " ; let count = count_carry ( a , b ) ; if ( count == 0 ) document . write ( " " + " " ) ; else if ( count == 1 ) document . write ( " " + " " ) ; else document . write ( count ) ;

Accumulator variables: count, len_a, len_b
Javascript program:
function printIndex ( str , s ) { var flag = false ; for ( var i = 0 ; i < str . length - s . length + 1 ; i ++ ) { if ( str . substring ( i , s . length + i ) == s ) { document . write ( i + " " ) ; flag = true ; } } if ( flag === false ) { document . write ( " " ) ; } } var str1 = " " ; var str2 = " " ; printIndex ( str1 , str2 ) ;

Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function getMaxOccurringChar ( str ) { let freq = new Array ( 26 ) ; for ( let i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = 0 ; } let max = - 1 ; let result = 0 ; let len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { if ( str [ i ] != ' ' ) { freq [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } } for ( let i = 0 ; i < 26 ; i ++ ) { if ( max < freq [ i ] ) { max = freq [ i ] ; result = String . fromCharCode ( i + ' ' . charCodeAt ( 0 ) ) ; } } return result ; } let str = " " . split ( " " ) ; document . write ( " " + getMaxOccurringChar ( str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function matchClosing ( X , start , end , open , close ) { let c = 1 ; let i = start + 1 ; while ( i <= end ) { if ( X [ i ] == open ) { c ++ ; } else if ( X [ i ] == close ) { c -- ; } if ( c == 0 ) { return i ; } i ++ ; } return i ; } function matchingOpening ( X , start , end , open , close ) { let c = - 1 ; let i = end - 1 ; while ( i >= start ) { if ( X [ i ] == open ) { c ++ ; } else if ( X [ i ] == close ) { c -- ; } if ( c == 0 ) { return i ; } i -- ; } return - 1 ; } function isBalanced ( X , n ) { let i , j = 0 , k , x , start , end ; for ( i = 0 ; i < n ; i ++ ) { if ( X [ i ] == ' ' ) { j = matchClosing ( X , i , n - 1 , ' ' , ' ' ) ; } else if ( X [ i ] == ' ' ) { j = matchClosing ( X , i , n - 1 , ' ' , ' ' ) ; } else if ( X [ i ] == ' ' ) { j = matchClosing ( X , i , n - 1 , ' ' , ' ' ) ; } else { if ( X [ i ] == ' ' ) { j = matchingOpening ( X , 0 , i , ' ' , ' ' ) ; } else if ( X [ i ] == ' ' ) { j = matchingOpening ( X , 0 , i , ' ' , ' ' ) ; } else if ( X [ i ] == ' ' ) { j = matchingOpening ( X , 0 , i , ' ' , ' ' ) ; } if ( j < 0 j >= i ) { return false ; } continue ; } if ( j >= n j < 0 ) { return false ; } start = i ; end = j ; for ( k = start + 1 ; k < end ; k ++ ) { if ( X [ k ] == ' ' ) { x = matchClosing ( X , k , end , ' ' , ' ' ) ; if ( ! ( k < x && x < end ) ) { return false ; } } else if ( X [ k ] == ' ' ) { x = matchingOpening ( X , start , k , ' ' , ' ' ) ; if ( ! ( start < x && x < k ) ) { return false ; } } if ( X [ k ] == ' ' ) { x = matchClosing ( X , k , end , ' ' , ' ' ) ; if ( ! ( k < x && x < end ) ) { return false ; } } else if ( X [ k ] == ' ' ) { x = matchingOpening ( X , start , k , ' ' , ' ' ) ; if ( ! ( start < x && x < k ) ) { return false ; } } if ( X [ k ] == ' ' ) { x = matchClosing ( X , k , end , ' ' , ' ' ) ; if ( ! ( k < x && x < end ) ) { return false ; } } else if ( X [ k ] == ' ' ) { x = matchingOpening ( X , start , k , ' ' , ' ' ) ; if ( ! ( start < x && x < k ) ) { return false ; } } } } return true ; } let X = " " . split ( " " ) ; let n = 6 ; if ( isBalanced ( X , n ) ) document . write ( " " ) ; else document . write ( " " ) ; let Y = " " . split ( " " ) ; n = 7 ; if ( isBalanced ( Y , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, k
Accumulator variables: c, i, k
Iterator variables: i, k
Javascript program:
function possibleToSort ( arr , n , str ) { let max_element = - 1 ; for ( let i = 0 ; i < str . length ; i ++ ) { max_element = Math . max ( max_element , arr [ i ] ) ; if ( str [ i ] == ' ' ) { if ( max_element > i + 1 ) return " " ; } } return " " ; } let arr = [ 1 , 2 , 5 , 3 , 4 , 6 ] ; let n = arr . Length ; let str = " " ; document . write ( possibleToSort ( arr , n , str ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findSubstring ( str , power ) { let map = new Map ( ) ; let curr_power = 0 ; let len = str . length ; for ( let i = 0 ; i < len ; i ++ ) { curr_power = curr_power + ( str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 1 ) ; if ( curr_power == power ) { document . write ( " " + " " + i + " " + power + " " ) ; return ; } if ( map . has ( curr_power - power ) ) { document . write ( " " + ( map . get ( curr_power - power ) + 1 ) + " " + i + " " + power + " " ) ; return ; } map . set ( curr_power , i ) ; } document . write ( " " ) ; } let str = " " ; let power = 36 ; findSubstring ( str , power ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPrimeString ( str ) { let len = str . length , n = 0 ; for ( let i = 0 ; i < len ; i ++ ) { n += str [ i ] . charCodeAt ( ) ; } if ( n <= 1 ) { return false ; } if ( n <= 3 ) { return true ; } if ( n % 2 == 0 n % 3 == 0 ) { return false ; } for ( let i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } let str = " " ; if ( isPrimeString ( str ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i, n
Iterator variables: i
Javascript program:
function countWays ( s ) { let count = new Array ( 26 ) ; count . fill ( 0 ) ; for ( let i = 0 ; i < s . length ; i ++ ) count [ s [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ++ ; count [ s [ 0 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] = 1 ; let ans = 1 ; for ( let i = 0 ; i < 26 ; ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ; return ans ; } let s = " " ; document . write ( countWays ( s ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function lexoString ( s , k ) { var n = s . length ; var v = [ ] ; var mp = { } ; for ( var i = 0 ; i < s . length ; i ++ ) { if ( ! mp . hasOwnProperty ( s [ i ] ) ) { mp [ s [ i ] ] = 1 ; v . push ( s [ i ] ) ; } } v . sort ( ( a , b ) => a - b ) ; if ( k > n ) { document . write ( s . join ( " " ) ) ; for ( var i = n ; i < k ; i ++ ) { document . write ( v [ 0 ] ) ; } } for ( var i = k - 1 ; i >= 0 ; i -- ) { if ( s [ i ] !== v [ v . length - 1 ] ) { for ( var j = 0 ; j < i ; j ++ ) { document . write ( s [ j ] ) ; } for ( var j = 0 ; j < v . length ; j ++ ) { if ( v [ j ] > s [ i ] ) { document . write ( v [ j ] ) ; break ; } } for ( var j = i + 1 ; j < k ; j ++ ) { document . write ( v [ 0 ] ) ; } return ; } } document . write ( " " + " " + k + " " ) ; } var s = " " ; var k = 3 ; lexoString ( s . split ( " " ) , k ) ;

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