dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function redistribute ( arr , n , x ) { arr . sort ( ) ; arr . reverse ( ) ; let i , sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( ( sum / ( i + 1 ) ) < x ) { document . write ( i ) ; break ; } } if ( i == n ) document . write ( n ) ; } let arr = [ 5 , 1 , 2 , 1 ] ; let x = 3 ; redistribute ( arr , 4 , x ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function final_element ( arr , n ) { var heap = [ ] ; for ( var i = 0 ; i < n ; i ++ ) heap . push ( arr [ i ] ) ; heap . sort ( ( a , b ) => a - b ) ; while ( heap . length > 1 ) { var X = heap [ heap . length - 1 ] ; heap . pop ( ) ; var Y = heap [ heap . length - 1 ] ; heap . pop ( ) ; if ( X != Y ) { var diff = Math . abs ( X - Y ) ; heap . push ( diff ) ; } heap . sort ( ( a , b ) => a - b ) ; } if ( heap . length == 1 ) { document . write ( heap [ heap . length - 1 ] ) ; } else { document . write ( " " ) ; } } var arr = [ 3 , 5 , 2 , 7 ] ; var n = arr . length ; final_element ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countFrequency ( str , ch ) { var count = 0 ; for ( var i = 0 ; i < str . length ; i ++ ) if ( str [ i ] == ch ) ++ count ; return count ; } function sortArr ( str ) { var n = str . length ; vp = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { vp [ i ] = [ countFrequency ( str , str [ i ] ) , str [ i ] ] ; } vp . sort ( ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( vp [ i ] [ 1 ] ) ; } let str = " " ; sortArr ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function arrSort ( a , n ) { var i , j , min , temp ; for ( i = 0 ; i < n - 1 ; i ++ ) { min = i ; for ( j = i + 1 ; j < n ; j ++ ) if ( a [ j ] < a [ min ] ) min = j ; temp = a [ i ] ; a [ i ] = a [ min ] ; a [ min ] = temp ; } } function maxSumArrangement ( A , R , N , M ) { var count = new Array ( N ) ; count . fill ( 0 ) ; for ( var i = 0 ; i < M ; i ++ ) { var l = R [ i ] [ 0 ] , r = R [ i ] [ 1 ] + 1 ; l -- ; r -- ; count [ l ] ++ ; if ( r < N ) count [ r ] -- ; } for ( var i = 1 ; i < N ; ++ i ) { count [ i ] += count [ i - 1 ] ; } var ans = 0 ; count . sort ( ) ; arrSort ( A , N ) ; for ( var i = N - 1 ; i >= 0 ; -- i ) { ans += A [ i ] * count [ i ] ; } return ans ; } var A = [ 2 , 6 , 10 , 1 , 5 , 6 ] ; var R = [ [ 1 , 3 ] , [ 4 , 6 ] , [ 3 , 4 ] ] ; var N = A . length ; var M = R . length ; document . write ( maxSumArrangement ( A , R , N , M ) ) ;

Index/key variables: i, j, l, min, r
Accumulator variables: ans, i, j, l, r
Iterator variables: i, j
Javascript program:
function findFactors ( n , k ) { let factors = [ ] ; for ( let i = 1 ; i <= Math . sqrt ( k ) ; i ++ ) { if ( k % i == 0 ) { if ( k / i == i && i <= n ) factors . push ( i ) ; else { if ( i <= n ) factors . push ( i ) ; if ( k / i <= n ) factors . push ( k / i ) ; } } } return factors ; } function findDigitSum ( a ) { for ( let i = 0 ; i < a . length ; i ++ ) { let c = 0 ; while ( a [ i ] > 0 ) { c += ( a [ i ] % 10 ) ; a [ i ] = Math . floor ( a [ i ] / 10 ) ; } a [ i ] = c ; } return a ; } function findMMaxDistinctDigitSum ( distinctDigitSum , m ) { let sum = 0 ; for ( let i = distinctDigitSum . length - 1 ; i >= 0 && m > 0 ; i -- , m -- ) sum += distinctDigitSum [ i ] ; return sum ; } function findDistinctMnumbers ( n , k , m ) { let factors = findFactors ( n , k ) ; let digitSum = findDigitSum ( factors ) ; digitSum . sort ( function ( a , b ) { return a - b ; } ) ; let hs1 = new Set ( digitSum ) ; let vect2 = Array . from ( hs1 ) ; return findMMaxDistinctDigitSum ( vect2 , m ) ; } let n = 100 , k = 80 , m = 4 ; document . write ( findDistinctMnumbers ( n , k , m ) ) ;

Index/key variables: i
Accumulator variables: c, i, m, sum
Iterator variables: i
Javascript program:
function partition ( objects , l , r , hash ) { let j = l - 1 ; let last_element = hash . get ( objects [ r ] ) ; for ( let i = l ; i < r ; i ++ ) { if ( hash . get ( objects [ i ] ) <= last_element ) { j ++ ; let temp = objects [ i ] ; objects [ i ] = objects [ j ] ; objects [ j ] = temp ; } } j ++ ; let temp = objects [ r ] ; objects [ r ] = objects [ j ] ; objects [ j ] = temp ; return j ; } function quicksort ( objects , l , r , hash ) { if ( l < r ) { let mid = partition ( objects , l , r , hash ) ; quicksort ( objects , l , mid - 1 , hash ) ; quicksort ( objects , mid + 1 , r , hash ) ; } } function sortObj ( objects ) { let hash = new Map ( ) ; hash . set ( " " , 1 ) ; hash . set ( " " , 2 ) ; hash . set ( " " , 3 ) ; quicksort ( objects , 0 , objects . length - 1 , hash ) ; for ( let i = 0 ; i < objects . length ; i ++ ) document . write ( objects [ i ] + " " ) ; } let objects = [ " " , " " , " " , " " , " " ] ; sortObj ( objects ) ;

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function productOfDigit ( n ) { var product = 1 ; while ( n > 0 ) { product *= n % 10 ; n = Math . floor ( n / 10 ) ; } return product ; } function sortArr ( arr , n ) { var vp = new Array ( n ) ; for ( var i = 0 ; i < n ; i ++ ) { vp [ i ] . push ( productOfDigit ( arr [ i ] ) ) ; vp [ i ] . push ( arr [ i ] ) ; } vp . sort ( ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( vp [ i ] [ 1 ] + " " ) ; } var arr = [ 12 , 10 , 102 , 31 , 15 ] ; var n = arr . length ; sortArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, product
Iterator variables: i
Javascript program:
function maxWater ( height , n ) { let maximum = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { let current = ( Math . min ( height [ i ] , height [ j ] ) * ( j - i - 1 ) ) ; maximum = Math . max ( maximum , current ) ; } } return maximum ; } let height = [ 2 , 1 , 3 , 4 , 6 , 5 ] ; let n = height . length ; document . write ( maxWater ( height , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function checkDivisors ( a , n ) { let X = Math . max ( ... a ) ; let b = [ ] ; for ( let i = 1 ; i * i <= X ; i ++ ) { if ( X % i == 0 ) { b . push ( i ) ; if ( parseInt ( X / i ) != i ) b . push ( parseInt ( X / i ) ) ; } } if ( b . length != n ) return false ; a . sort ( ( x , y ) => x - y ) ; b . sort ( ( x , y ) => x - y ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( b [ i ] != a [ i ] ) return false ; } return true ; } let arr = [ 8 , 1 , 2 , 12 , 48 , 6 , 4 , 24 , 16 , 3 ] ; let N = arr . length ; if ( checkDivisors ( arr , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findKthNode ( u , v , n , val , V , k ) { var g = Array . from ( Array ( V ) , ( ) => Array ( ) ) ; for ( var i = 0 ; i < n ; i ++ ) { g [ u [ i ] ] . push ( [ val [ v [ i ] ] , v [ i ] ] ) ; g [ v [ i ] ] . push ( [ val [ u [ i ] ] , u [ i ] ] ) ; } for ( var i = 0 ; i < V ; i ++ ) { if ( g [ i ] . length > 0 ) g [ i ] . sort ( ) ; if ( k <= g [ i ] . length ) document . write ( g [ i ] [ g [ i ] . length - k ] [ 1 ] + " " ) ; else document . write ( " " ) ; } return ; } var V = 3 ; var val = [ 2 , 4 , 3 ] ; var u = [ 0 , 0 , 1 ] ; var v = [ 2 , 1 , 2 ] ; var n = u . length ; var k = 2 ; findKthNode ( u , v , n , val , V , k ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function mod ( x ) { if ( x >= 0 ) return x ; return - x ; } function findSquare ( n ) { let points = [ [ 1 , 2 ] , [ - 3 , 4 ] , [ 1 , 78 ] , [ - 3 , - 7 ] ] ; let a = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { let x , y ; x = points [ i ] [ 0 ] ; y = points [ i ] [ 1 ] ; a [ i ] = Math . max ( mod ( x ) , mod ( y ) ) ; } a . sort ( function ( a , b ) { return a - b } ) ; let index = ( Math . floor ( n / 2 ) - 1 ) ; document . write ( " " + a [ index ] ) ; } let N ; N = 4 ; findSquare ( N ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
function minSum ( arr , n ) { arr . sort ( ) ; let x = arr [ Math . floor ( n / 2 ) ] ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += Math . abs ( arr [ i ] - x ) ; return sum ; } let arr = [ 1 , 3 , 9 , 3 , 6 ] ; let n = arr . length ; document . write ( minSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function odd_even ( arr , n ) { var odd_indexes = [ ] ; var even_indexes = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) odd_indexes . push ( arr [ i ] ) ; else even_indexes . push ( arr [ i ] ) ; } odd_indexes . sort ( ) ; even_indexes . sort ( ) ; for ( var i = 0 ; i < odd_indexes . length ; i ++ ) document . write ( odd_indexes [ i ] + " " ) ; for ( var i = 0 ; i < even_indexes . length ; i ++ ) document . write ( even_indexes [ i ] + " " ) ; } var arr = [ 3 , 2 , 7 , 6 , 8 ] ; var n = arr . length ; odd_even ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countPairs ( a , n ) { let map = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { map . set ( a [ i ] , 1 ) ; } let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( map . get ( a [ i ] ) < 1 ) continue ; let cur = 1 ; while ( cur <= a [ i ] ) cur <<= 1 ; if ( map . has ( cur - a [ i ] ) ) { if ( cur - a [ i ] == a [ i ] && map . get ( a [ i ] ) == 1 ) continue ; count ++ ; map . set ( cur - a [ i ] , map . get ( cur - a [ i ] ) - 1 ) ; map . set ( a [ i ] , map . get ( a [ i ] ) - 1 ) ; } } return count ; } let a = [ 3 , 11 , 14 , 5 , 13 ] ; let n = a . length ; document . write ( countPairs ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countMaxPos ( arr ) { let n = arr . length ; let map = new Map ( ) ; for ( let x of arr ) { if ( map . has ( x ) ) map . set ( x , map . get ( x ) + 1 ) ; else map . set ( x , 1 ) ; } let max_freq = 0 ; for ( let entry of map ) max_freq = Math . max ( max_freq , entry [ 1 ] ) ; console . log ( max_freq , n ) return n - max_freq ; } let arr = [ 20 , 30 , 10 , 50 , 40 ] ; document . write ( countMaxPos ( arr ) ) ;

Iterator variables: entry, x
Javascript program:
function sortMultiples ( arr , n , x ) { var v = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % x == 0 ) { v . push ( arr [ i ] ) ; } } v . sort ( ( a , b ) => a - b ) ; var j = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % x == 0 ) arr [ i ] = v [ j ++ ] ; } } var arr = [ 125 , 3 , 15 , 6 , 100 , 5 ] ; var x = 5 ; var n = arr . length ; sortMultiples ( arr , n , x ) ; for ( var i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function absSumDidd ( a ) { a . sort ( ( a , b ) => a - b ) ; var midValue = a [ a . length / 2 ] ; var sum = 0 ; for ( var i = 0 ; i < a . length ; i ++ ) { sum = sum + Math . abs ( a [ i ] - midValue ) ; } return sum ; } var arr = [ 5 , 11 , 14 , 10 , 17 , 15 ] ; document . write ( absSumDidd ( arr ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printRLE ( s ) { for ( var i = 0 ; i < s . length ; i ++ ) { var count = 1 ; while ( i + 1 < s . length && s . charAt ( i ) == s . charAt ( i + 1 ) ) { i ++ ; count ++ ; } document . write ( s . charAt ( i ) + " " + count + " " ) ; } document . write ( " " ) ; } printRLE ( " " ) ; printRLE ( " " ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function shortestChainLen ( start , target , D ) { if ( start == target ) return 0 ; if ( ! D . has ( target ) ) return 0 ; let level = 0 , wordlength = start . length ; let Q = [ ] ; Q . push ( start ) ; while ( Q . length != 0 ) { ++ level ; let sizeofQ = Q . length ; for ( let i = 0 ; i < sizeofQ ; ++ i ) { let word = Q [ 0 ] . split ( " " ) ; Q . shift ( ) ; for ( let pos = 0 ; pos < wordlength ; ++ pos ) { let orig_char = word [ pos ] ; for ( let c = ' ' . charCodeAt ( 0 ) ; c <= ' ' . charCodeAt ( 0 ) ; ++ c ) { word [ pos ] = String . fromCharCode ( c ) ; if ( word . join ( " " ) == target ) return level + 1 ; if ( ! D . has ( word . join ( " " ) ) ) continue ; D . delete ( word . join ( " " ) ) ; Q . push ( word . join ( " " ) ) ; } word [ pos ] = orig_char ; } } } return 0 ; } let D = new Set ( ) ; D . add ( " " ) ; D . add ( " " ) ; D . add ( " " ) ; D . add ( " " ) ; D . add ( " " ) ; D . add ( " " ) ; D . add ( " " ) ; let start = " " ; let target = " " ; document . write ( " " + shortestChainLen ( start , target , D ) ) ;

Index/key variables: pos
Iterator variables: c, i, pos
Javascript program:
if ( inMST [ v ] == false && key [ v ] > weight ) { key [ v ] = weight ; value = [ key [ v ] , v ] ; pq . push ( value ) ; parent [ v ] = u ; }

Index/key variables: v
Javascript program:
function addEdge ( adj , u , v , wt ) { adj [ u ] . push ( [ v , wt ] ) ; adj [ v ] . push ( [ u , wt ] ) ; return adj ; } function printGraph ( adj , V ) { let v = 0 , w = 0 ; for ( let u = 0 ; u < V ; u ++ ) { document . write ( " " + u + " " ) ; for ( let it = 0 ; it < adj [ u ] . length ; it ++ ) { v = adj [ u ] [ it ] [ 0 ] ; w = adj [ u ] [ it ] [ 1 ] ; document . write ( " " + v + " " + w + " " ) } } } let V = 5 ; let adj = new Array ( V ) ; for ( let i = 0 ; i < V ; i ++ ) { adj [ i ] = [ ] ; } adj = addEdge ( adj , 0 , 1 , 10 ) adj = addEdge ( adj , 0 , 4 , 20 ) adj = addEdge ( adj , 1 , 2 , 30 ) adj = addEdge ( adj , 1 , 3 , 40 ) adj = addEdge ( adj , 1 , 4 , 50 ) adj = addEdge ( adj , 2 , 3 , 60 ) adj = addEdge ( adj , 3 , 4 , 70 ) printGraph ( adj , V ) ;

Index/key variables: i, it, u, v
Accumulator variables: i, it, u
Iterator variables: i, it, u
Javascript program:
function maxindex ( dist , n ) { let mi = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( dist [ i ] > dist [ mi ] ) mi = i ; } return mi ; } function selectKcities ( n , weights , k ) { let dist = new Array ( n ) ; let centers = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { dist [ i ] = Number . MAX_VALUE ; } let max = 0 ; for ( let i = 0 ; i < k ; i ++ ) { centers . push ( max ) ; for ( let j = 0 ; j < n ; j ++ ) { dist [ j ] = Math . min ( dist [ j ] , weights [ max ] [ j ] ) ; } max = maxindex ( dist , n ) ; } document . write ( dist [ max ] + " " ) ; for ( let i = 0 ; i < centers . length ; i ++ ) { document . write ( centers [ i ] + " " ) ; } document . write ( " " ) ; } let n = 4 ; let weights = [ [ 0 , 4 , 8 , 5 ] , [ 4 , 0 , 10 , 7 ] , [ 8 , 10 , 0 , 9 ] , [ 5 , 7 , 9 , 0 ] ] let k = 2 selectKcities ( n , weights , k )

Index/key variables: i, j, max, mi
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let V = 4 ; function multiply ( A , B , C ) { for ( let i = 0 ; i < V ; i ++ ) { for ( let j = 0 ; j < V ; j ++ ) { C [ i ] [ j ] = 0 ; for ( let k = 0 ; k < V ; k ++ ) C [ i ] [ j ] += A [ i ] [ k ] * B [ k ] [ j ] ; } } } function getTrace ( graph ) { let trace = 0 ; for ( let i = 0 ; i < V ; i ++ ) trace += graph [ i ] [ i ] ; return trace ; } function triangleInGraph ( graph ) { let aux2 = new Array ( V ) ; let aux3 = new Array ( V ) ; for ( let i = 0 ; i < V ; ++ i ) { aux2 [ i ] = new Array ( V ) ; aux3 [ i ] = new Array ( V ) ; for ( let j = 0 ; j < V ; ++ j ) { aux2 [ i ] [ j ] = aux3 [ i ] [ j ] = 0 ; } } multiply ( graph , graph , aux2 ) ; multiply ( graph , aux2 , aux3 ) ; let trace = getTrace ( aux3 ) ; return ( trace / 6 ) ; } let graph = [ [ 0 , 1 , 1 , 0 ] , [ 1 , 0 , 1 , 1 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 1 , 0 ] ] ; document . write ( " " + triangleInGraph ( graph ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k, trace
Iterator variables: i, j, k
Javascript program:
var SIZE = 26 function binomialCoeff ( n , k ) { var res = 1 ; if ( k > n - k ) k = n - k ; for ( var i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } function countSubsequences ( str1 , str2 ) { var freq1 = Array ( SIZE ) . fill ( 0 ) , freq2 = Array ( SIZE ) . fill ( 0 ) ; var n1 = str1 . length ; var n2 = str2 . length ; for ( var i = 0 ; i < n1 ; i ++ ) freq1 [ str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( var i = 0 ; i < n2 ; i ++ ) freq2 [ str2 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; var count = 1 ; for ( var i = 0 ; i < SIZE ; i ++ ) if ( freq2 [ i ] != 0 ) { if ( freq2 [ i ] <= freq1 [ i ] ) count = count * binomialCoeff ( freq1 [ i ] , freq2 [ i ] ) ; else return 0 ; } return count ; } var str1 = " " ; var str2 = " " ; document . write ( " " + countSubsequences ( str1 , str2 ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
let fwd = new Array ( 100 ) ; let bwd = new Array ( 100 ) ; function preProcess ( a , b ) { let n = a . length ; let j = 0 ; for ( let i = 1 ; i <= a . length ; i ++ ) { if ( j < b . length && a [ i - 1 ] == b [ j ] ) { j ++ ; } fwd [ i ] = j ; } j = 0 ; for ( let i = a . length ; i >= 1 ; i -- ) { if ( j < b . length && a [ i - 1 ] == b [ b . length - j - 1 ] ) { j ++ ; } bwd [ i ] = j ; } } function query ( a , b , x , y ) { if ( ( x - 1 + a . length - y ) < b . length ) { document . write ( " " ) ; return ; } if ( fwd [ x - 1 ] + bwd [ y + 1 ] >= b . length ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let a = " " , b = " " ; preProcess ( a , b ) ; let x = 2 , y = 5 ; query ( a , b , x , y ) ; x = 3 ; y = 6 ; query ( a , b , x , y ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function findOccurrences ( str1 , substr1 ) { let counter = 0 ; for ( let i = 0 ; i < str1 . length ; i ++ ) { if ( str1 [ i ] == substr1 [ 0 ] ) { for ( let j = i + 1 ; j < str1 . length ; j ++ ) { if ( str1 [ j ] == substr1 [ 1 ] ) { for ( let k = j + 1 ; k < str1 . length ; k ++ ) { if ( str1 [ k ] == substr1 [ 2 ] ) counter ++ ; } } } } } return counter ; } let str1 = " " ; let substr1 = " " ; document . write ( findOccurrences ( str1 , substr1 ) ) ;

Index/key variables: i, j, k
Accumulator variables: counter, i, j, k
Iterator variables: i, j, k
Javascript program:
function findOccurrences ( str , substr ) { let n = str . length ; let preLeft = new Array ( n ) ; preLeft . fill ( 0 ) ; let preRight = new Array ( n ) ; preRight . fill ( 0 ) ; if ( str [ 0 ] == substr [ 0 ] ) preLeft [ 0 ] ++ ; for ( let i = 1 ; i < n ; i ++ ) { if ( str [ i ] == substr [ 0 ] ) preLeft [ i ] = preLeft [ i - 1 ] + 1 ; else preLeft [ i ] = preLeft [ i - 1 ] ; } if ( str [ n - 1 ] == substr [ 2 ] ) preRight [ n - 1 ] ++ ; for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( str [ i ] == substr [ 2 ] ) preRight [ i ] = preRight [ i + 1 ] + 1 ; else preRight [ i ] = preRight [ i + 1 ] ; } let counter = 0 ; for ( let i = 1 ; i < n - 1 ; i ++ ) { if ( str [ i ] == str [ 1 ] ) { let total = preLeft [ i - 1 ] * preRight [ i + 1 ] ; counter += total ; } } return counter ; } let str = " " ; let substr = " " ; document . write ( findOccurrences ( str , substr ) ) ;

Index/key variables: i
Accumulator variables: counter, i
Iterator variables: i
Javascript program:
function largestPalin ( num , n ) { if ( n <= 3 ) return ; let mid = Math . floor ( n / 2 ) - 1 ; let rightMax = new Array ( mid + 1 ) ; let right ; rightMax [ mid ] = - 1 ; right = mid ; for ( let i = mid - 1 ; i >= 0 ; i -- ) { if ( num [ i ] < num [ right ] ) rightMax [ i ] = right ; else { rightMax [ i ] = - 1 ; right = i ; } } for ( let i = 0 ; i <= mid ; i ++ ) { if ( rightMax [ i ] != - 1 ) { swap ( num , i , rightMax [ i ] ) ; swap ( num , n - i - 1 , n - rightMax [ i ] - 1 ) ; break ; } } } function swap ( arr , i , j ) { let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } let num = " " . split ( " " ) ; let n = num . length ; largestPalin ( num , n ) ; document . write ( " " + ( num ) . join ( " " ) ) ;

Index/key variables: i, j, mid, right
Accumulator variables: i
Iterator variables: i
Javascript program:
function compute ( str , n ) { let reverseAlphabet = " " ; let l = str . length ; let answer = " " ; for ( let i = 0 ; i < n ; i ++ ) answer = answer + str [ i ] ; for ( let i = n ; i < l ; i ++ ) answer = answer + reverseAlphabet [ str [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ] ; return answer ; } let str = " " ; let n = 4 ; document . write ( compute ( str , n - 1 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findString ( str , n , k ) { if ( k == 0 ) { document . write ( str ) ; ; return ; } var str2 = str ; var p = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( str2 . charAt ( i ) != ' ' ) { str2 = str2 . substring ( 0 , i ) + ' ' + str2 . substring ( i + 1 ) ; p ++ ; if ( p == k ) break ; } } if ( p < k ) { for ( i = n - 1 ; i >= 0 ; i -- ) if ( str . charAt ( i ) == ' ' ) { str2 = str2 . substring ( 0 , i ) + ' ' + str2 . substring ( i + 1 ) ; p ++ ; if ( p == k ) break ; } } document . write ( str2 ) ; } var str = " " ; var n = str . length ; var k = 2 ; findString ( str , n , k ) ;

Accumulator variables: i, p
Iterator variables: i
Javascript program:
let SIZE = 26 ; function isVowel ( ch ) { if ( ch == ' ' ch == ' ' ch == ' ' ch == ' ' ch == ' ' ) { return true ; } return false ; } function createAltStr ( str1 , str2 , start , l ) { let finalStr = " " ; for ( let i = 0 , j = start ; j < l ; i ++ , j ++ ) { finalStr = ( finalStr + str1 [ i ] ) + str2 [ j ] ; } return finalStr ; } function findAltStr ( str ) { let char_freq = new Array ( SIZE ) ; for ( let i = 0 ; i < SIZE ; i ++ ) char_freq [ i ] = 0 ; let nv = 0 , nc = 0 ; let vstr = " " , cstr = " " ; let l = str . length ; for ( let i = 0 ; i < l ; i ++ ) { let ch = str [ i ] ; if ( isVowel ( ch ) ) { nv ++ ; } else { nc ++ ; } char_freq [ ch . charCodeAt ( 0 ) - 97 ] ++ ; } if ( Math . abs ( nv - nc ) >= 2 ) { return " " ; } for ( let i = 0 ; i < SIZE ; i ++ ) { let ch = String . fromCharCode ( i + 97 ) ; for ( let j = 1 ; j <= char_freq [ i ] ; j ++ ) { if ( isVowel ( ch ) ) { vstr += ch ; } else { cstr += ch ; } } } if ( nv > nc ) { return ( vstr [ 0 ] + createAltStr ( cstr , vstr , 1 , nv ) ) ; } if ( nc > nv ) { return ( cstr [ 0 ] + createAltStr ( vstr , cstr , 1 , nc ) ) ; } if ( cstr [ 0 ] < vstr [ 0 ] ) { return createAltStr ( cstr , vstr , 0 , nv ) ; } return createAltStr ( vstr , cstr , 0 , nc ) ; } let str = " " ; document . write ( findAltStr ( str ) ) ;

Index/key variables: i, j
Accumulator variables: cstr, i, j, nc, nv, vstr
Iterator variables: i, j
Javascript program:
let SIZE = 100 ; function base64Decoder ( encoded , len_str ) { let decoded_String ; decoded_String = new Array ( SIZE ) ; let i , j , k = 0 ; let num = 0 ; let count_bits = 0 ; for ( i = 0 ; i < len_str ; i += 4 ) { num = 0 ; count_bits = 0 ; for ( j = 0 ; j < 4 ; j ++ ) { if ( encoded [ i + j ] != ' ' ) { num = num << 6 ; count_bits += 6 ; } if ( encoded [ i + j ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && encoded [ i + j ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) num = num | ( encoded [ i + j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; else if ( encoded [ i + j ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && encoded [ i + j ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) num = num | ( encoded [ i + j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 26 ) ; else if ( encoded [ i + j ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && encoded [ i + j ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) num = num | ( encoded [ i + j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + 52 ) ; else if ( encoded [ i + j ] == ' ' ) num = num | 62 ; else if ( encoded [ i + j ] == ' ' ) num = num | 63 ; else { num = num >> 2 ; count_bits -= 2 ; } } while ( count_bits != 0 ) { count_bits -= 8 ; decoded_String [ k ++ ] = String . fromCharCode ( ( num >> count_bits ) & 255 ) ; } } return ( decoded_String ) ; } let encoded_String = " " . split ( " " ) ; let len_str = encoded_String . length ; len_str -= 1 ; document . write ( " " + ( encoded_String ) . join ( " " ) + " " ) ; document . write ( " " + base64Decoder ( encoded_String , len_str ) . join ( " " ) + " " ) ;

Accumulator variables: count_bits, i, j, k, len_str
Iterator variables: i, j