dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function lcs ( dp , a , b , m , n ) { if ( m < 0 n < 0 ) { return 0 ; } if ( dp [ m ] [ n ] != - 1 ) return dp [ m ] [ n ] ; let ans = 0 ; if ( a [ m ] == b [ n ] ) { ans = ( a [ m ] . charCodeAt ( 0 ) - 48 ) + lcs ( dp , a , b , m - 1 , n - 1 ) ; } else ans = Math . max ( lcs ( dp , a , b , m - 1 , n ) , lcs ( dp , a , b , m , n - 1 ) ) ; dp [ m ] [ n ] = ans ; return ans ; } function costOfString ( str ) { let cost = 0 ; for ( let i = 0 ; i < str . length ; i ++ ) cost += ( str [ i ] . charCodeAt ( 0 ) - 48 ) ; return cost ; } let a = " " ; let b = " " ; let dp = new Array ( 101 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 101 ) ; for ( let j = 0 ; j < 101 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } document . write ( ( costOfString ( a ) + costOfString ( b ) - 2 * lcs ( dp , a , b , a . length - 1 , b . length - 1 ) ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: cost, i, j
Iterator variables: i, j
Javascript program:
function maxSubArraySum ( arr , size ) { var max_so_far = arr [ 0 ] ; var curr_max = arr [ 0 ] ; for ( var i = 1 ; i < size ; i ++ ) { curr_max = Math . max ( arr [ i ] , curr_max + arr [ i ] ) ; max_so_far = Math . max ( max_so_far , curr_max ) ; } return max_so_far ; } function lenOfLongSubarrWithGivenSum ( arr , n , k ) { var um = new Map ( ) ; var sum = 0 , maxLen = 0 ; for ( var i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( sum == k ) maxLen = i + 1 ; if ( ! um . has ( sum ) ) um . set ( sum , i ) ; if ( um . has ( sum - k ) ) { if ( maxLen < ( i - um . get ( sum - k ) ) ) maxLen = i - um . get ( sum - k ) } } return maxLen ; } function lenLongSubarrWithMaxSum ( arr , n ) { var maxSum = maxSubArraySum ( arr , n ) ; return lenOfLongSubarrWithGivenSum ( arr , n , maxSum ) ; } var arr = [ 5 , - 2 , - 1 , 3 , - 4 ] ; var n = arr . length ; document . write ( " " + lenLongSubarrWithMaxSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function GCD ( a , b ) { if ( b == 0 ) return a ; return GCD ( b , a % b ) ; } function makePairs ( pairs , a , b ) { for ( i = a ; i <= b ; i ++ ) { var sumOfDigits = 0 , k = i ; while ( k > 0 ) { sumOfDigits += k % 10 ; k = parseInt ( k / 10 ) ; } if ( sumOfDigits <= 162 ) pairs . push ( sumOfDigits ) ; } } function countCoPrime ( a , b ) { var pairs = [ ] ; makePairs ( pairs , a , b ) ; var count = 0 ; for ( i = 0 ; i < pairs . length ; i ++ ) for ( j = i + 1 ; j < pairs . length ; j ++ ) if ( GCD ( pairs [ i ] , pairs [ j ] ) == 1 ) count ++ ; return count ; } var a = 12 , b = 15 ; document . write ( countCoPrime ( a , b ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j, sumOfDigits
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function recursive ( idx , sum , tight , st , dp , num ) { if ( idx == num ) { return sum == 0 ? 1 : 0 ; } if ( dp [ idx ] [ tight ] [ sum ] != - 1 ) return dp [ idx ] [ tight ] [ sum ] ; let newTight ; let ans = 0 ; let d ; for ( d = 0 ; d < 10 ; ++ d ) { newTight = 0 ; if ( tight == 1 && st [ idx ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) < d ) continue ; if ( tight == 1 && st [ idx ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) == d ) newTight = 1 ; if ( sum >= d ) ans += recursive ( idx + 1 , sum - d , newTight , st , dp , num ) ; } return dp [ idx ] [ tight ] [ sum ] = ans ; } function formArray ( N ) { let dp = new Array ( 20 ) ; for ( let i = 0 ; i < 20 ; i ++ ) { dp [ i ] = new Array ( 2 ) ; for ( let j = 0 ; j < 2 ; j ++ ) { dp [ i ] [ j ] = new Array ( 166 ) ; for ( let k = 0 ; k < 166 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } let st = ( N ) . toString ( ) ; let num = st . length ; let arr = [ ] ; for ( let i = 1 ; i <= 162 ; ++ i ) { arr . push ( recursive ( 0 , i , 1 , st , dp , num ) ) ; } return arr ; } function findPair ( a , b ) { let arr_smaller = formArray ( a - 1 ) ; let arr_greater = formArray ( b ) ; for ( let i = 0 ; i < arr_greater . length ; ++ i ) { arr_greater [ i ] -= arr_smaller [ i ] ; } let ans = 0 ; for ( let i = 1 ; i <= 162 ; ++ i ) { for ( let j = i + 1 ; j <= 162 ; ++ j ) { if ( gcd ( i , j ) == 1 ) { ans = ( ans + arr_greater [ i - 1 ] * arr_greater [ j - 1 ] ) ; } } } return ans ; } let a = 12 , b = 15 ; document . write ( findPair ( a , b ) ) ;

Index/key variables: i, idx, j, k, sum, tight
Accumulator variables: ans, i, j, k
Iterator variables: d, i, j, k
Javascript program:
function factors ( n ) { let v = [ ] ; v . push ( 1 ) ; for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v . push ( i ) ; if ( Math . floor ( n / i ) != i ) { v . push ( Math . floor ( n / i ) ) ; } } } return v ; } function check ( n ) { let v = [ ] ; v = factors ( n ) ; v . sort ( function ( a , b ) { return a - b ; } ) ; let r = v . length ; let subset = new Array ( r + 1 ) ; for ( let i = 0 ; i < r + 1 ; i ++ ) { subset [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < n + 1 ; j ++ ) { subset [ i ] [ j ] = false ; } } for ( let i = 0 ; i <= r ; i ++ ) subset [ i ] [ 0 ] = true ; for ( let i = 1 ; i <= n ; i ++ ) subset [ 0 ] [ i ] = false ; for ( let i = 1 ; i <= r ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { if ( j < v [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; else { subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - v [ i - 1 ] ] ; } } } if ( ( subset [ r ] [ n ] ) == false ) return false ; else return true ; } let n = 40 ; if ( check ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, n, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let fib = new Array ( 43 ) ; function fibonacci ( ) { fib [ 0 ] = 1 ; fib [ 1 ] = 2 ; for ( let i = 2 ; i < 43 ; i ++ ) fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } function rec ( x , y , last ) { if ( y == 0 ) { if ( x == 0 ) return 1 ; return 0 ; } let sum = 0 ; for ( let i = last ; i >= 0 && fib [ i ] * y >= x ; i -- ) { if ( fib [ i ] > x ) continue ; sum += rec ( x - fib [ i ] , y - 1 , i ) ; } return sum ; } fibonacci ( ) ; let n = 13 , k = 3 ; document . write ( " " + rec ( n , k , 42 ) ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function minimumCost ( cost , n ) { let dp = new Array ( n ) ; if ( n == 1 ) return cost [ 0 ] ; dp [ 0 ] = cost [ 0 ] ; dp [ 1 ] = cost [ 1 ] ; for ( let i = 2 ; i < n ; i ++ ) { dp [ i ] = Math . min ( dp [ i - 1 ] , dp [ i - 2 ] ) + cost [ i ] ; } return Math . min ( dp [ n - 2 ] , dp [ n - 1 ] ) ; } let a = [ 16 , 19 , 10 , 12 , 18 ] ; let n = a . length ; document . write ( minimumCost ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumCost ( cost , n ) { let dp1 = 0 , dp2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let dp0 = cost [ i ] + Math . min ( dp1 , dp2 ) ; dp2 = dp1 ; dp1 = dp0 ; } return Math . min ( dp1 , dp2 ) ; } let a = [ 2 , 5 , 3 , 1 , 7 , 3 , 4 ] ; let n = a . length ; document . write ( minimumCost ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let size = 1000 ; function maxCost ( a , m , n , dp ) { if ( n < 0 m < 0 ) return - 1e9 ; else if ( m == 0 && n == 0 ) return 0 ; else if ( dp [ m ] [ n ] != - 1 ) return dp [ m ] [ n ] ; else { let num = m + n ; if ( ( num & ( num - 1 ) ) == 0 ) return dp [ m ] [ n ] = a [ m ] [ n ] + maxCost ( a , m - 1 , n - 1 , dp ) ; else return dp [ m ] [ n ] = ( a [ m ] [ n ] + Math . max ( maxCost ( a , m - 1 , n , dp ) , maxCost ( a , m , n - 1 , dp ) ) ) ; } } function answer ( a , n ) { let dp = new Array ( size ) ; for ( let i = 0 ; i < size ; i ++ ) { dp [ i ] = new Array ( size ) ; for ( let j = 0 ; j < size ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return maxCost ( a , n - 1 , n - 1 , dp ) ; } let a = [ [ 1 , 2 , 3 , 1 ] , [ 4 , 5 , 6 , 1 ] , [ 7 , 8 , 9 , 1 ] , [ 1 , 1 , 1 , 1 ] ] ; let n = 4 ; document . write ( answer ( a , n ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function editDistanceWith2Ops ( X , Y ) { let m = X . length , n = Y . length ; let L = new Array ( m + 1 ) ; for ( let i = 0 ; i < L . length ; i ++ ) { L [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < L [ i ] . length ; j ++ ) { L [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i <= m ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) { L [ i ] [ j ] = 0 ; } else if ( X [ i - 1 ] == Y [ j - 1 ] ) { L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; } else { L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } } let lcs = L [ m ] [ n ] ; return ( m - lcs ) + ( n - lcs ) ; } let X = " " , Y = " " ; document . write ( editDistanceWith2Ops ( X , Y ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countPaths ( n ) { let zB = 1 ; let zADC = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { let nzB = zADC * 3 ; let nzADC = ( zADC * 2 + zB ) ; zB = nzB ; zADC = nzADC ; } return zB ; } let n = 3 ; document . write ( countPaths ( n ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function sumSubSequence ( arr , len , m ) { let sum = 0 ; for ( let x = 0 ; x < arr . length ; x ++ ) { sum += arr [ x ] ; } let dp = new Array ( len + 1 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( sum + 1 ) ; for ( let j = 0 ; j < dp [ i ] . length ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i <= len ; i ++ ) dp [ i ] [ 0 ] ++ ; for ( let i = 1 ; i <= len ; i ++ ) { dp [ i ] [ arr [ i - 1 ] ] ++ ; for ( let j = 1 ; j <= sum ; j ++ ) { if ( dp [ i - 1 ] [ j ] > 0 ) { dp [ i ] [ j ] ++ ; dp [ i ] [ j + arr [ i - 1 ] ] ++ ; } } } let count = 0 ; for ( let j = 1 ; j <= sum ; j ++ ) if ( dp [ len ] [ j ] > 0 ) if ( j % m == 0 ) count += dp [ len ] [ j ] ; return count ; } let arr = [ 1 , 2 , 3 ] ; let m = 3 ; let len = arr . length ; document . write ( sumSubSequence ( arr , len , m ) + " " ) ;

Index/key variables: i, j, len, x
Accumulator variables: count, i, j, sum, x
Iterator variables: i, j, x
Javascript program:
function lds ( arr , n ) { let lds = new Array ( n ) ; let i , j , max = 0 ; for ( i = 0 ; i < n ; i ++ ) lds [ i ] = 1 ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] < arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ; for ( i = 0 ; i < n ; i ++ ) if ( max < lds [ i ] ) max = lds [ i ] ; return max ; } let arr = [ 15 , 27 , 14 , 38 , 63 , 55 , 46 , 65 , 85 ] ; let n = arr . length ; document . write ( " " + lds ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var MAX = 100 function CountDecreasingPathsCell ( mat , dp , n , x , y ) { if ( dp [ x ] [ y ] != - 1 ) return dp [ x ] [ y ] ; var delta = [ [ 0 , 1 ] , [ 1 , 0 ] , [ - 1 , 0 ] , [ 0 , - 1 ] ] ; var newx , newy ; var ans = 1 ; for ( var i = 0 ; i < 4 ; i ++ ) { newx = x + delta [ i ] [ 0 ] ; newy = y + delta [ i ] [ 1 ] ; if ( newx >= 0 && newx < n && newy >= 0 && newy < n && mat [ newx ] [ newy ] < mat [ x ] [ y ] ) { ans += CountDecreasingPathsCell ( mat , dp , n , newx , newy ) ; } } dp [ x ] [ y ] = ans ; return ans ; } function countDecreasingPathsMatrix ( n , mat ) { var dp = Array . from ( Array ( MAX ) , ( ) => Array ( MAX ) ) ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = 0 ; j < n ; j ++ ) dp [ i ] [ j ] = - 1 ; var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = 0 ; j < n ; j ++ ) sum += CountDecreasingPathsCell ( mat , dp , n , i , j ) ; return sum ; } var n = 2 ; var mat = [ [ 1 , 2 ] , [ 1 , 3 ] ] ; document . write ( countDecreasingPathsMatrix ( n , mat ) ) ;

Index/key variables: i, j, newx, newy, x, y
Accumulator variables: ans, i, j, sum
Iterator variables: i, j
Javascript program:
var MAX = 100 ; function binomialCoeff ( C , n ) { for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = Math . min ( i , n ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } } function sumOfproduct ( n ) { var sum = 0 ; var C = Array ( MAX ) . fill ( 0 ) ; binomialCoeff ( C , n ) ; for ( var i = 0 ; i <= n ; i ++ ) sum += C [ i ] * C [ i + 1 ] ; return sum ; } var n = 3 ; document . write ( sumOfproduct ( n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
MAX = 100 function binomialCoeff ( n , C ) { for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = Math . min ( i , n ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } } function summation ( n ) { C = Array ( MAX ) . fill ( 0 ) ; binomialCoeff ( n , C ) ; var sum = 0 ; for ( var i = 0 ; i <= n ; i ++ ) sum += ( i * C [ i ] ) ; return sum ; } var n = 2 ; document . write ( summation ( n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function binomialCoeff ( n , k ) { var C = Array ( k + 1 ) . fill ( 0 ) ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = Math . min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } function countArray ( N , K ) { return binomialCoeff ( K - 1 , N - 1 ) ; } var N = 2 , K = 3 ; document . write ( countArray ( N , K ) ) ;

Index/key variables: j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
class data { constructor ( element , position ) { this . element = element ; this . position = position ; } } ; function findMinElement ( arr , n ) { let result = new data ( ) ; let prefixSum = new Array ( n ) ; let suffixSum = new Array ( n ) ; prefixSum [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { prefixSum [ i ] = prefixSum [ i - 1 ] + arr [ i ] ; } suffixSum [ n - 1 ] = arr [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; i -- ) { suffixSum [ i ] = suffixSum [ i + 1 ] + arr [ i ] ; } let min = suffixSum [ 0 ] ; let pos = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( Math . abs ( suffixSum [ i + 1 ] - prefixSum [ i ] ) < min ) { min = Math . abs ( suffixSum [ i + 1 ] - prefixSum [ i ] ) ; if ( suffixSum [ i + 1 ] < prefixSum [ i ] ) pos = i + 1 ; else pos = i ; } } result . element = min ; result . position = pos ; return result ; } let arr = [ 10 , 1 , 2 , 3 , 4 ] ; let n = arr . length ; let values ; values = findMinElement ( arr , n ) ; document . write ( " " + values . element + " " + values . position ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: data
Javascript program:
var N = 100 ; function count ( n , c , a , b ) { var need = Array ( N ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { a [ i + n ] = a [ i ] ; b [ i + n ] = b [ i ] ; } var s = 0 ; var tank = 0 ; for ( var i = 0 ; i < 2 * n ; i ++ ) { tank += a [ i ] ; tank = Math . min ( tank , c ) ; tank -= b [ i ] ; if ( tank < 0 ) { tank = 0 ; s = i + 1 ; } } if ( s >= n ) return 0 ; var ans = 1 ; need [ s + n ] = 0 ; for ( var i = 1 ; i < n ; i ++ ) { var id = s + n - i ; need [ id ] = Math . max ( 0 , need [ id + 1 ] + b [ id ] - Math . min ( a [ id ] , c ) ) ; if ( need [ id ] == 0 ) ans ++ ; } return ans ; } var n = 3 ; var c = 3 ; var a = [ 3 , 1 , 2 ] ; var b = [ 2 , 2 , 2 ] ; document . write ( count ( n , c , a , b ) ) ;

Index/key variables: i, id
Accumulator variables: ans, i, tank
Iterator variables: i
Javascript program:
function printEqualSumSets ( arr , n ) { var i , currSum ; var sum = 0 ; for ( var i = 0 ; i < arr . length ; i ++ ) { sum += arr [ i ] ; } if ( sum & 1 ) { document . write ( " " ) ; return ; } var k = sum >> 1 ; var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( k + 1 ) ) ; for ( i = 1 ; i <= k ; i ++ ) dp [ 0 ] [ i ] = false ; for ( i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = true ; for ( i = 1 ; i <= n ; i ++ ) { for ( currSum = 1 ; currSum <= k ; currSum ++ ) { dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ; if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ] | dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ; } } var set1 = [ ] , set2 = [ ] ; if ( ! dp [ n ] [ k ] ) { document . write ( " " ) ; return ; } i = n ; currSum = k ; while ( i > 0 && currSum >= 0 ) { if ( dp [ i - 1 ] [ currSum ] ) { i -- ; set2 . push ( arr [ i ] ) ; } else if ( dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ) { i -- ; currSum -= arr [ i ] ; set1 . push ( arr [ i ] ) ; } } document . write ( " " ) ; for ( i = 0 ; i < set1 . length ; i ++ ) document . write ( set1 [ i ] + " " ) ; document . write ( " " ) ; for ( i = 0 ; i < set2 . length ; i ++ ) document . write ( set2 [ i ] + " " ) ; } var arr = [ 5 , 5 , 1 , 11 ] ; var n = arr . length ; printEqualSumSets ( arr , n ) ;

Index/key variables: currSum, i, k, n
Accumulator variables: currSum, i, sum
Iterator variables: currSum, i
Javascript program:
function largestSumOfAverages ( A , K ) { var n = A . length ; var pre_sum = Array ( n + 1 ) . fill ( - 1 ) ; pre_sum [ 0 ] = 0 ; for ( var i = 0 ; i < n ; i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ; var dp = Array ( n ) . fill ( - 1 ) ; var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ; for ( k = 0 ; k < K - 1 ; k ++ ) for ( i = 0 ; i < n ; i ++ ) for ( j = i + 1 ; j < n ; j ++ ) dp [ i ] = Math . max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ; return dp [ 0 ] ; } var A = [ 9 , 1 , 2 , 3 , 9 ] ; document . write ( largestSumOfAverages ( A , K ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function findMaxVal ( arr , n , num , maxLimit ) { var ind ; var val ; var dp = Array . from ( Array ( n ) , ( ) => Array ( maxLimit + 1 ) ) ; for ( ind = 0 ; ind < n ; ind ++ ) { for ( val = 0 ; val <= maxLimit ; val ++ ) { if ( ind == 0 ) { if ( num - arr [ ind ] == val num + arr [ ind ] == val ) { dp [ ind ] [ val ] = 1 ; } else { dp [ ind ] [ val ] = 0 ; } } else { if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) { dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] || dp [ ind - 1 ] [ val + arr [ ind ] ] ; } else if ( val - arr [ ind ] >= 0 ) { dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ; } else if ( val + arr [ ind ] <= maxLimit ) { dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ; } else { dp [ ind ] [ val ] = 0 ; } } } } for ( val = maxLimit ; val >= 0 ; val -- ) { if ( dp [ n - 1 ] [ val ] ) { return val ; } } return - 1 ; } var num = 1 ; var arr = [ 3 , 10 , 6 , 4 , 5 ] ; var n = arr . length ; var maxLimit = 15 ; document . write ( findMaxVal ( arr , n , num , maxLimit ) ) ;

Index/key variables: ind, val
Accumulator variables: ind, val
Iterator variables: ind, val
Javascript program:
function gen ( n ) { if ( n == 0 ) return 0 ; else if ( n == 1 ) return 1 ; else if ( n % 2 == 0 ) return 4 * gen ( parseInt ( n / 2 , 10 ) ) ; else if ( n % 2 == 1 ) return 4 * gen ( parseInt ( n / 2 , 10 ) ) + 1 ; return 0 ; } function moserDeBruijn ( n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( gen ( i ) + " " ) ; document . write ( " " ) ; } let n = 15 ; document . write ( " " + n + " " + " " + " " ) ; moserDeBruijn ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let A = [ [ 2 ] , [ 3 , 9 ] , [ 1 , 6 , 7 ] ] ; function minSumPath ( ) { let memo = [ ] ; let n = A . length - 1 ; for ( let i = 0 ; i < A [ n ] . length ; i ++ ) memo [ i ] = A [ n ] [ i ] ; for ( let i = A . length - 2 ; i >= 0 ; i -- ) for ( let j = 0 ; j < A [ i ] . length ; j ++ ) memo [ j ] = A [ i ] [ j ] + Math . min ( memo [ j ] , memo [ j + 1 ] ) ; return memo [ 0 ] ; } document . write ( minSumPath ( ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function isPossible ( index , sum ) { if ( index == n ) { if ( ( sum % M ) == 0 ) return true ; return false ; } let placeAdd = isPossible ( index + 1 , sum + arr [ index ] ) ; let placeMinus = isPossible ( index + 1 , sum - arr [ index ] ) ; if ( placeAdd placeMinus ) return true ; return false ; }

Index/key variables: index
Javascript program:
let MAX = 100 ; let dp = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { dp [ i ] = new Array ( MAX ) ; } function countRemovals ( a , i , j , k ) { if ( i >= j ) return 0 ; else if ( ( a [ j ] - a [ i ] ) <= k ) return 0 ; else if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ; else if ( ( a [ j ] - a [ i ] ) > k ) { dp [ i ] [ j ] = 1 + Math . min ( countRemovals ( a , i + 1 , j , k ) , countRemovals ( a , i , j - 1 , k ) ) ; } return dp [ i ] [ j ] ; } function removals ( a , n , k ) { a . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < MAX ; i ++ ) { for ( let j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } if ( n == 1 ) return 0 ; else return countRemovals ( a , 0 , n - 1 , k ) ; } let a = [ 1 , 3 , 4 , 9 , 10 , 11 , 12 , 17 , 20 ] ; let n = a . length ; let k = 4 ; document . write ( removals ( a , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findInd ( key , i , n , k , arr ) { var start , end , mid , ind = - 1 ; start = i + 1 ; end = n - 1 ; while ( start < end ) { mid = start + ( end - start ) / 2 ; if ( arr [ mid ] - key <= k ) { ind = mid ; start = mid + 1 ; } else { end = mid ; } } return ind ; } function removals ( arr , n , k ) { var i , j , ans = n - 1 ; arr . sort ( ( a , b ) => a - b ) ; for ( i = 0 ; i < n ; i ++ ) { j = findInd ( arr [ i ] , i , n , k , arr ) ; if ( j != - 1 ) { ans = Math . min ( ans , n - ( j - i + 1 ) ) ; } } return ans ; } var a = [ 1 , 3 , 4 , 9 , 10 , 11 , 12 , 17 , 20 ] ; var n = a . length ; var k = 4 ; document . write ( removals ( a , n , k ) ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
var dp = Array . from ( Array ( 1000 ) , ( ) => Array ( 1000 ) ) ; function sum ( a , i , j ) { var ans = 0 ; for ( var m = i ; m <= j ; m ++ ) ans = ( ans + a [ m ] ) % 100 ; return ans ; } function solve ( a , i , j ) { if ( i == j ) return 0 ; if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ; dp [ i ] [ j ] = 1000000000 ; for ( var k = i ; k < j ; k ++ ) { dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , ( solve ( a , i , k ) + solve ( a , k + 1 , j ) + ( sum ( a , i , k ) * sum ( a , k + 1 , j ) ) ) ) ; } return dp [ i ] [ j ] ; } function initialize ( n ) { for ( var i = 0 ; i <= n ; i ++ ) for ( var j = 0 ; j <= n ; j ++ ) dp [ i ] [ j ] = - 1 ; } var a = [ 40 , 60 , 20 ] ; var n = a . length ; initialize ( n ) ; document . write ( solve ( a , 0 , n - 1 ) ) ;

Index/key variables: i, j, m
Accumulator variables: i, j, k, m
Iterator variables: i, j, k, m
Javascript program:
function reverseFibonacci ( n ) { let a = [ ] ; a [ 0 ] = 0 ; a [ 1 ] = 1 ; for ( let i = 2 ; i < n ; i ++ ) { a [ i ] = a [ i - 2 ] + a [ i - 1 ] ; } for ( let i = n - 1 ; i >= 0 ; i -- ) { document . write ( a [ i ] + " " ) ; } } let n = 5 ; reverseFibonacci ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function check ( s1 , s2 ) { let n = s1 . length ; let m = s2 . length ; let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) { dp [ i ] = new Array ( m + 1 ) ; for ( let j = 0 ; j <= m ; j ++ ) { dp [ i ] [ j ] = false ; } } dp [ 0 ] [ 0 ] = true ; for ( let i = 0 ; i < s1 . length ; i ++ ) { for ( let j = 0 ; j <= s2 . length ; j ++ ) { if ( dp [ i ] [ j ] ) { if ( j < s2 . length && ( s1 [ i ] . toUpperCase ( ) == s2 [ j ] ) ) dp [ i + 1 ] [ j + 1 ] = true ; if ( ! ( s1 [ i ] == s1 [ i ] . toUpperCase ( ) ) ) dp [ i + 1 ] [ j ] = true ; } } } return ( dp [ n ] [ m ] ) ; } let s1 = " " ; let s2 = " " ; if ( check ( s1 , s2 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function find_prob ( N , P ) { let dp = [ ] ; dp [ 0 ] = 1 ; dp [ 1 ] = 0 ; dp [ 2 ] = P ; dp [ 3 ] = 1 - P ; for ( let i = 4 ; i <= N ; ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ; return ( dp [ N ] ) ; } let n = 5 ; let p = 0.2 ; document . write ( find_prob ( n , p ) ) ;

Index/key variables: N, i
Iterator variables: i