dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
var N = 100 var dp = Array . from ( Array ( N ) , ( ) => Array ( 3 ) ) ; var v = Array . from ( Array ( N ) , ( ) => Array ( 3 ) ) ; function findCnt ( s , i , r ) { if ( i == s . length ) { if ( r == 0 ) return 1 ; else return 0 ; } if ( v [ i ] [ r ] ) return dp [ i ] [ r ] ; v [ i ] [ r ] = 1 ; dp [ i ] [ r ] = findCnt ( s , i + 1 , ( r * 2 + ( s [ i ] - ' ' ) ) % 3 ) + findCnt ( s , i + 1 , r ) ; return dp [ i ] [ r ] ; } var s = " " ; document . write ( ( findCnt ( s , 0 , 0 ) - 1 ) ) ;

Index/key variables: i, r
Javascript program:
function minCount ( arr , n , k ) { var ans = 0 ; var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; sum -= k ; var l = 0 ; var r = 0 ; var tot = 0 ; while ( l < n ) { if ( tot <= sum ) { ans = Math . max ( ans , r - l ) ; if ( r == n ) break ; tot += arr [ r ++ ] ; } else { tot -= arr [ l ++ ] ; } } return ( n - ans ) ; } var arr = [ 1 , 11 , 5 , 5 ] ; var n = arr . length ; var k = 11 ; document . write ( minCount ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, l, r, sum, tot
Iterator variables: i
Javascript program:
var N = 401 var dp = Array . from ( Array ( N ) , ( ) => Array ( N ) ) ; var v = Array . from ( Array ( N ) , ( ) => Array ( N ) ) ; function minMergeCost ( i , j , arr ) { if ( i == j ) return 0 ; if ( v [ i ] [ j ] ) return dp [ i ] [ j ] ; v [ i ] [ j ] = 1 ; var x = dp [ i ] [ j ] ; x = 1000000000 ; var tot = 0 ; for ( var k = i ; k <= j ; k ++ ) tot += arr [ k ] ; for ( var k = i + 1 ; k <= j ; k ++ ) { x = Math . min ( x , tot + minMergeCost ( i , k - 1 , arr ) + minMergeCost ( k , j , arr ) ) ; } return x ; } var arr = [ 1 , 3 , 7 ] ; var n = arr . length ; document . write ( minMergeCost ( 0 , n - 1 , arr ) ) ;

Index/key variables: i, j, k
Accumulator variables: k, tot
Iterator variables: k
Javascript program:
var maxSize = 50 ; var dp = Array ( maxSize ) ; var v = Array ( maxSize ) ; function expectedSteps ( x ) { if ( x == 0 ) return 0 ; if ( x <= 5 ) return 6 ; if ( v [ x ] ) return dp [ x ] ; v [ x ] = 1 ; dp [ x ] = 1 + ( expectedSteps ( x - 1 ) + expectedSteps ( x - 2 ) + expectedSteps ( x - 3 ) + expectedSteps ( x - 4 ) + expectedSteps ( x - 5 ) + expectedSteps ( x - 6 ) ) / 6 ; return dp [ x ] ; } var n = 10 ; document . write ( expectedSteps ( n - 1 ) . toFixed ( 5 ) ) ;

Index/key variables: x
Javascript program:
function countSubSeq ( str , len ) { var ans = 0 ; var mul = 1 ; for ( var i = 0 ; i < len ; i ++ ) { if ( str [ i ] == ' ' ) ans += mul ; mul *= 2 ; } return ans ; } var str = " " ; var len = str . length ; document . write ( countSubSeq ( str , len ) ) ;

Index/key variables: i
Accumulator variables: ans, i, mul
Iterator variables: i
Javascript program:
var V_SUM_MAX = 1000 var N_MAX = 100 var W_MAX = 10000000 var dp = Array . from ( Array ( V_SUM_MAX + 1 ) , ( ) => Array ( N_MAX ) ) ; var v = Array . from ( Array ( V_SUM_MAX + 1 ) , ( ) => Array ( N_MAX ) ) ; function solveDp ( r , i , w , val , n ) { if ( r <= 0 ) return 0 ; if ( i == n ) return W_MAX ; if ( v [ r ] [ i ] ) return dp [ r ] [ i ] ; v [ r ] [ i ] = 1 ; dp [ r ] [ i ] = Math . min ( solveDp ( r , i + 1 , w , val , n ) , w [ i ] + solveDp ( r - val [ i ] , i + 1 , w , val , n ) ) ; return dp [ r ] [ i ] ; } function maxWeight ( w , val , n , c ) { for ( var i = V_SUM_MAX ; i >= 0 ; i -- ) { if ( solveDp ( i , 0 , w , val , n ) <= c ) { return i ; } } return 0 ; } var w = [ 3 , 4 , 5 ] ; var val = [ 30 , 50 , 60 ] ; var n = w . length ; var C = 8 ; document . write ( maxWeight ( w , val , n , C ) ) ;

Index/key variables: i, r
Accumulator variables: i
Iterator variables: i
Javascript program:
let sz = 100005 ; let n ; let tree = new Array ( sz ) ; let subtree_size = new Array ( sz ) ; let vis = new Array ( sz ) ; function AddEdge ( a , b ) { tree [ a ] . push ( b ) ; tree [ b ] . push ( a ) ; } function dfs ( node ) { vis [ node ] = 1 ; subtree_size [ node ] = 1 ; for ( let child = 0 ; child < tree [ node ] . length ; child ++ ) { if ( vis [ tree [ node ] [ child ] ] == 0 ) { subtree_size [ node ] += dfs ( tree [ node ] [ child ] ) ; } } return subtree_size [ node ] ; } function contribution ( node , ans ) { vis [ node ] = 1 ; for ( let child = 0 ; child < tree [ node ] . length ; child ++ ) { if ( vis [ tree [ node ] [ child ] ] == 0 ) { ans += ( subtree_size [ tree [ node ] [ child ] ] * ( n - subtree_size [ tree [ node ] [ child ] ] ) ) ; ans = contribution ( tree [ node ] [ child ] , ans ) ; } } return ans ; } function getSum ( ) { for ( let i = 0 ; i < vis . length ; i ++ ) { vis [ i ] = 0 ; } dfs ( 0 ) ; let ans = 0 ; for ( let i = 0 ; i < vis . length ; i ++ ) { vis [ i ] = 0 ; } ans = contribution ( 0 , ans ) ; return ans ; } n = 5 ; for ( let i = 0 ; i < sz ; i ++ ) { tree [ i ] = [ ] ; } AddEdge ( 0 , 1 ) ; AddEdge ( 0 , 2 ) ; AddEdge ( 1 , 3 ) ; AddEdge ( 1 , 4 ) ; document . write ( getSum ( ) ) ;

Index/key variables: a, b, child, i, node
Accumulator variables: ans, child, i
Iterator variables: child, i
Javascript program:
let N = 3 ; function numberOfCells ( mat ) { let row = new Array ( N ) ; let col = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { row [ i ] = new Array ( N ) ; col [ i ] = new Array ( N ) ; for ( let j = 0 ; j < N ; j ++ ) { row [ i ] [ j ] = 0 ; col [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = N - 1 ; j >= 0 ; j -- ) { if ( mat [ i ] [ j ] == 1 ) { row [ i ] [ j ] = ( j + 1 < N ) ? row [ i ] [ j + 1 ] : true ; } else { row [ i ] [ j ] = false ; } } } for ( let j = 0 ; j < N ; j ++ ) { for ( let i = N - 1 ; i >= 0 ; i -- ) { if ( mat [ i ] [ j ] == 1 ) { col [ i ] [ j ] = ( i + 1 < N ) ? col [ i + 1 ] [ j ] : true ; } else { col [ i ] [ j ] = false ; } } } let cnt = 0 ; for ( let i = 0 ; i < N - 1 ; i ++ ) { for ( let j = 0 ; j < N - 1 ; j ++ ) { if ( row [ i ] [ j ] && col [ i ] [ j ] ) { cnt ++ ; } } } for ( let i = 0 ; i < N ; i ++ ) { if ( col [ i ] [ N - 1 ] ) cnt ++ ; } for ( let j = 0 ; j < N - 1 ; j ++ ) { if ( row [ N - 1 ] [ j ] ) cnt ++ ; } return cnt ; } let mat = [ [ 0 , 1 , 1 ] , [ 0 , 1 , 1 ] , [ 0 , 1 , 1 ] ] ; document . write ( numberOfCells ( mat ) ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function maxSumSubarray ( arr , size ) { let max_so_far = Number . MIN_SAFE_INTEGER , max_ending_here = 0 ; for ( let i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + arr [ i ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } function getUpdatedArray ( arr , copy , i ) { for ( let j = 0 ; j <= ( i / 2 ) ; j ++ ) { copy [ j ] = arr [ i - j ] ; copy [ i - j ] = arr [ j ] ; } return ; } function maxSum ( arr , size ) { let resSum = Number . MIN_SAFE_INTEGER ; resSum = Math . max ( resSum , maxSumSubarray ( arr , size ) ) ; let copyArr = arr ; for ( let i = 1 ; i < size ; i ++ ) { getUpdatedArray ( arr , copyArr , i ) ; resSum = Math . max ( resSum , maxSumSubarray ( copyArr , size ) ) ; } arr . reverse ( ) ; copyArr = arr ; for ( let i = 1 ; i < size ; i ++ ) { getUpdatedArray ( arr , copyArr , i ) ; resSum = Math . max ( resSum , maxSumSubarray ( copyArr , size ) ) ; } resSum += 6 return resSum ; } let arr = [ - 9 , 21 , 24 , 24 , - 51 , - 6 , 17 , - 42 , - 39 , 33 ] ; let size = arr . length ; document . write ( maxSum ( arr , size ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, resSum
Iterator variables: i, j
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; } function MaxGCD ( a , n ) { var Prefix = Array ( n + 2 ) . fill ( 0 ) ; var Suffix = Array ( n + 2 ) . fill ( 0 ) ; var i ; Prefix [ 1 ] = a [ 0 ] ; for ( i = 2 ; i <= n ; i ++ ) { Prefix [ i ] = gcd ( Prefix [ i - 1 ] , a [ i - 1 ] ) ; } Suffix [ n ] = a [ n - 1 ] ; for ( i = n - 1 ; i >= 1 ; i -- ) { Suffix [ i ] = gcd ( Suffix [ i + 1 ] , a [ i - 1 ] ) ; } var ans = Math . max ( Suffix [ 2 ] , Prefix [ n - 1 ] ) ; for ( i = 2 ; i < n ; i ++ ) { ans = Math . max ( ans , gcd ( Prefix [ i - 1 ] , Suffix [ i + 1 ] ) ) ; } return ans ; } var a = [ 6 , 7 , 8 ] ; n = a . length ; document . write ( MaxGCD ( a , n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function sumOfProduct ( arr , n , k ) { let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < dp [ i ] . length ; j ++ ) { dp [ i ] [ j ] = 0 ; } } let cur_sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { dp [ 1 ] [ i ] = arr [ i - 1 ] ; cur_sum += arr [ i - 1 ] ; } for ( let i = 2 ; i <= k ; i ++ ) { let temp_sum = 0 ; for ( let j = 1 ; j <= n ; j ++ ) { cur_sum -= dp [ i - 1 ] [ j ] ; dp [ i ] [ j ] = arr [ j - 1 ] * cur_sum ; temp_sum += dp [ i ] [ j ] ; } cur_sum = temp_sum ; } return cur_sum ; } let arr = [ 1 , 2 , 3 , 4 ] ; let n = arr . length ; let k = 2 ; document . write ( sumOfProduct ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: cur_sum, i, j, temp_sum
Iterator variables: i, j
Javascript program:
let mod = 1e9 + 7 ; function subsequence ( S , T , n , m ) { let dp = new Array ( ) for ( let i = 0 ; i < n + 1 ; i ++ ) { let temp = [ ] ; for ( let j = 0 ; j < m + 1 ; j ++ ) { temp . push ( [ ] ) } dp . push ( temp ) } for ( let i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = 1 ; for ( let j = 0 ; j <= m ; j ++ ) dp [ 0 ] [ j ] = 1 ; for ( let i = 1 ; i <= n ; ++ i ) { for ( let j = 1 ; j <= m ; ++ j ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] - dp [ i - 1 ] [ j - 1 ] ; if ( S [ i - 1 ] == T [ j - 1 ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ j - 1 ] ; dp [ i ] [ j ] += mod ; dp [ i ] [ j ] %= mod ; } } return dp [ n ] [ m ] ; } let S = [ 1 , 1 ] ; let n = S . length ; let T = [ 1 , 1 ] ; let m = T . length ; document . write ( subsequence ( S , T , n , m ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findMax ( arr , n ) { var res = 0 ; var i , j ; for ( i = 0 ; i < n ; i ++ ) { var count = 0 ; for ( j = 0 ; j < i ; j ++ ) { if ( arr [ j ] % arr [ i ] == 0 ) count += 1 ; } res = Math . max ( count , res ) ; } return res ; } var arr = [ 8 , 1 , 28 , 4 , 2 , 6 , 7 ] ; var n = arr . length ; document . write ( findMax ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function findMax ( arr , n ) { var divisible = Array ( n ) . fill ( false ) ; var res = 0 ; for ( var i = n - 1 ; i > 0 ; i -- ) { if ( divisible [ i ] ) continue ; var cnt = 0 ; for ( var j = 0 ; j < i ; j ++ ) { if ( ( arr [ j ] % arr [ i ] ) == 0 ) { divisible [ j ] = true ; cnt ++ ; } } res = Math . max ( res , cnt ) ; } return res ; } var arr = [ 8 , 1 , 28 , 4 , 2 , 6 , 7 ] ; var n = arr . length ; document . write ( findMax ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
var maxN = 20 var maxM = 10 var dp = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; var v = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; function findCnt ( arr , i , curr , n , m ) { if ( i == n ) { if ( curr == 0 ) return 1 ; else return 0 ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; dp [ i ] [ curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr + arr [ i ] ) % m , n , m ) ; return dp [ i ] [ curr ] ; } var arr = [ 3 , 3 , 3 , 3 ] ; var n = arr . length ; var m = 6 ; document . write ( findCnt ( arr , 0 , 0 , n , m ) - 1 ) ;

Index/key variables: curr, i
Javascript program:
var maxN = 20 var maxM = 64 var dp = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; var v = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; function findLen ( arr , i , curr , n , m ) { if ( i == n ) { if ( curr == m ) return 0 ; else return - 1 ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; var l = findLen ( arr , i + 1 , curr , n , m ) ; var r = findLen ( arr , i + 1 , curr arr [ i ] , n , m ) ; dp [ i ] [ curr ] = l ; if ( r != - 1 ) dp [ i ] [ curr ] = Math . max ( dp [ i ] [ curr ] , r + 1 ) ; return dp [ i ] [ curr ] ; } var arr = [ 3 , 7 , 2 , 3 ] ; var n = arr . length ; var m = 3 ; var ans = findLen ( arr , 0 , 0 , n , m ) ; if ( ans == - 1 ) document . write ( 0 ) ; else document . write ( ans ) ;

Index/key variables: curr, i
Javascript program:
var maxN = 20 var maxM = 64 var dp = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; var v = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; function findLen ( arr , i , curr , n , m ) { if ( i == n ) { if ( curr == m ) return 0 ; else return - 1 ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; var l = findLen ( arr , i + 1 , curr , n , m ) ; var r = findLen ( arr , i + 1 , curr & arr [ i ] , n , m ) ; dp [ i ] [ curr ] = l ; if ( r != - 1 ) dp [ i ] [ curr ] = Math . max ( dp [ i ] [ curr ] , r + 1 ) ; return dp [ i ] [ curr ] ; } var arr = [ 3 , 7 , 2 , 3 ] ; var n = arr . length ; var m = 3 ; var ans = findLen ( arr , 0 , ( ( 1 << 8 ) - 1 ) , n , m ) ; if ( ans == - 1 ) document . write ( 0 ) ; else document . write ( ans ) ;

Index/key variables: curr, i
Javascript program:
var maxN = 20 var maxM = 64 var dp = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) . fill ( 0 ) ) ; var v = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) . fill ( false ) ) ; function findLen ( arr , i , curr , n , m ) { if ( i == n ) { if ( ! curr ) return 0 ; else return - 1 ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; var l = findLen ( arr , i + 1 , curr , n , m ) ; var r = findLen ( arr , i + 1 , ( curr + arr [ i ] ) % m , n , m ) ; dp [ i ] [ curr ] = l ; if ( r != - 1 ) dp [ i ] [ curr ] = Math . max ( dp [ i ] [ curr ] , r + 1 ) ; return dp [ i ] [ curr ] ; } var arr = [ 3 , 2 , 2 , 1 ] ; var n = arr . length ; var m = 3 ; document . write ( findLen ( arr , 0 , 0 , n , m ) ) ;

Index/key variables: curr, i
Javascript program:
var maxN = 20 var maxSum = 50 var minSum = 50 var base = 50 var dp = Array . from ( Array ( maxN ) , ( ) => Array ( maxSum + minSum ) ) ; var v = Array . from ( Array ( maxN ) , ( ) => Array ( maxSum + minSum ) ) ; function findCnt ( arr , i , required_sum , n ) { if ( i == n ) { if ( required_sum == 0 ) return 1 ; else return 0 ; } if ( v [ i ] [ required_sum + base ] ) return dp [ i ] [ required_sum + base ] ; v [ i ] [ required_sum + base ] = 1 ; dp [ i ] [ required_sum + base ] = findCnt ( arr , i + 1 , required_sum , n ) + findCnt ( arr , i + 1 , required_sum - arr [ i ] , n ) ; return dp [ i ] [ required_sum + base ] ; } var arr = [ 3 , 3 , 3 , 3 ] ; var n = arr . length ; var x = 6 ; document . write ( findCnt ( arr , 0 , x , n ) ) ;

Index/key variables: i
Javascript program:
var maxN = 20 var maxM = 64 var dp = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; var v = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; function findCnt ( arr , i , curr , n , m ) { if ( i == n ) { return ( curr == m ) ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = 1 ; dp [ i ] [ curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr arr [ i ] ) , n , m ) ; return dp [ i ] [ curr ] ; } var arr = [ 2 , 3 , 2 ] ; var n = arr . length ; var m = 3 ; document . write ( findCnt ( arr , 0 , 0 , n , m ) ) ;

Index/key variables: curr, i
Javascript program:
var maxN = 20 ; var maxM = 64 ; var dp1 = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; var v1 = Array . from ( Array ( maxN ) , ( ) => Array ( maxM ) ) ; function findCnt ( arr , i , curr , n , m ) { if ( i == n ) { return ( curr == m ) ; } if ( v1 [ i ] [ curr ] ) return dp1 [ i ] [ curr ] ; v1 [ i ] [ curr ] = 1 ; dp1 [ i ] [ curr ] = findCnt ( arr , i + 1 , curr , n , m ) + findCnt ( arr , i + 1 , ( curr & arr [ i ] ) , n , m ) ; return dp1 [ i ] [ curr ] ; } var arr = [ 0 , 0 , 0 ] ; var n = arr . length ; var m = 0 ; document . write ( findCnt ( arr , 0 , ( ( 1 << 6 ) - 1 ) , n , m ) ) ;

Index/key variables: curr, i
Javascript program:
var MOD = parseInt ( 1e9 + 7 ) ; function modulo_13 ( s , n ) { var dp = Array ( n + 1 ) . fill ( ) . map ( ( ) => Array ( 13 ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = 1 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < 10 ; j ++ ) { var nxt = s . charAt ( i ) - ' ' ; if ( s . charAt ( i ) == ' ' ) nxt = j ; for ( k = 0 ; k < 13 ; k ++ ) { var rem = ( 10 * k + nxt ) % 13 ; dp [ i + 1 ] [ rem ] += dp [ i ] [ k ] ; dp [ i + 1 ] [ rem ] %= MOD ; } if ( s . charAt ( i ) != ' ' ) break ; } } return parseInt ( dp [ n ] [ 5 ] ) ; } var s = " " ; var n = s . length ; document . write ( modulo_13 ( s , n ) ) ;

Index/key variables: i, k, n, rem
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function LISusingLCS ( seq ) { let n = seq . length ; let L = new Array ( n + 1 ) ; for ( let i = 0 ; i < ( n + 1 ) ; i ++ ) { L [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < ( n + 1 ) ; j ++ ) { L [ i ] [ j ] = 0 ; } } let sortedseq = [ ... seq ] ; sortedseq . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i <= n ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i ] [ j ] = 0 ; else if ( seq [ i - 1 ] == sortedseq [ 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 ] ) ; } } return L [ n ] [ n ] ; } let sequence = [ 12 , 34 , 1 , 5 , 40 , 80 ] ; document . write ( LISusingLCS ( sequence ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function count_numbers ( k , n ) { let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) dp [ i ] = new Array ( 2 ) ; dp [ 1 ] [ 0 ] = 0 ; dp [ 1 ] [ 1 ] = k - 1 ; for ( let i = 2 ; i <= n ; i ++ ) { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 1 ] ; dp [ i ] [ 1 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] ) * ( k - 1 ) ; } return dp [ n ] [ 0 ] + dp [ n ] [ 1 ] ; } let k = 10 ; let n = 3 ; document . write ( count_numbers ( k , n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function divideArray ( arr , n , k ) { var dp = Array . from ( Array ( 500 ) , ( ) => Array ( 500 ) . fill ( 0 ) ) ; k -= 1 ; for ( var i = n - 1 ; i >= 0 ; i -- ) { for ( var j = 0 ; j <= k ; j ++ ) { dp [ i ] [ j ] = 1000000000 ; var max_ = - 1 , sum = 0 ; for ( var l = i ; l < n ; l ++ ) { max_ = Math . max ( max_ , arr [ l ] ) ; sum += arr [ l ] ; var diff = ( l - i + 1 ) * max_ - sum ; if ( j > 0 ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , diff + dp [ l + 1 ] [ j - 1 ] ) ; else dp [ i ] [ j ] = diff ; } } } return dp [ 0 ] [ k ] ; } var arr = [ 2 , 9 , 5 , 4 , 8 , 3 , 6 ] ; var n = arr . length ; var k = 2 ; document . write ( divideArray ( arr , n , k ) + " " ) ;

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l, sum
Iterator variables: i, j, l
Javascript program:
function cntSubsets ( arr , n ) { var max = Math . pow ( 2 , n ) ; var result = 0 ; for ( var i = 0 ; i < max ; i ++ ) { var counter = i ; if ( counter & ( counter >> 1 ) ) continue ; result ++ ; } return result ; } var arr = [ 3 , 5 , 7 ] ; var n = arr . length ; document . write ( cntSubsets ( arr , n ) ) ;

Accumulator variables: i, result
Iterator variables: i
Javascript program:
function cntSubsets ( arr , n ) { var a = Array ( n ) ; var b = Array ( n ) ; a [ 0 ] = b [ 0 ] = 1 ; for ( var i = 1 ; i < n ; i ++ ) { a [ i ] = a [ i - 1 ] + b [ i - 1 ] ; b [ i ] = a [ i - 1 ] ; } var result = a [ n - 1 ] + b [ n - 1 ] ; return result ; } var arr = [ 3 , 5 , 7 ] ; var n = arr . length ; document . write ( cntSubsets ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function perfix_calculate ( A , row , col ) { let n = A . length ; let m = A [ 0 ] . length ; for ( let i = 0 ; i < n ; ++ i ) { row [ i ] [ 0 ] = A [ i ] [ 0 ] ; } for ( let i = 0 ; i < n ; ++ i ) { for ( let j = 1 ; j < m ; ++ j ) { row [ i ] [ j ] = row [ i ] [ j - 1 ] + A [ i ] [ j ] ; } } for ( let i = 0 ; i < m ; ++ i ) { col [ 0 ] [ i ] = A [ 0 ] [ i ] ; } for ( let i = 0 ; i < m ; ++ i ) { for ( let j = 1 ; j < n ; ++ j ) { col [ j ] [ i ] = A [ j ] [ i ] + col [ j - 1 ] [ i ] ; } } } function perimeter ( i , j , k , row , col , A ) { let row_s , col_s ; if ( j == 0 ) row_s = 0 ; else row_s = row [ i ] [ j - 1 ] ; if ( i == 0 ) col_s = 0 ; else col_s = col [ i - 1 ] [ j ] ; let upper_row = row [ i ] [ j + k ] - row_s ; let left_col = col [ i + k ] [ j ] - col_s ; if ( j == 0 ) row_s = 0 ; else row_s = row [ i + k ] [ j - 1 ] ; if ( i == 0 ) col_s = 0 ; else col_s = col [ i - 1 ] [ j + k ] ; let lower_row = row [ i + k ] [ j + k ] - row_s ; let right_col = col [ i + k ] [ j + k ] - col_s ; let sum = upper_row + lower_row + left_col + right_col ; sum -= ( A [ i ] [ j ] + A [ i + k ] [ j ] + A [ i ] [ j + k ] + A [ i + k ] [ j + k ] ) ; return sum ; } function maxPerimeter ( A ) { let n = A . length ; let m = A [ 0 ] . length ; let row = new Array ( n ) ; let col = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { row [ i ] = new Array ( m ) ; col [ i ] = new Array ( m ) ; } perfix_calculate ( A , row , col ) ; let maxPer = 0 ; for ( let i = 0 ; i < n ; ++ i ) { for ( let j = 0 ; j < m ; ++ j ) { for ( let k = 0 ; k < Math . min ( n - i , m - j ) ; ++ k ) { let perimtr = perimeter ( i , j , k , row , col , A ) ; maxPer = Math . max ( maxPer , perimtr ) ; } } } return maxPer ; } let A = [ [ 1 , 1 , 0 ] , [ 1 , 1 , 1 ] , [ 0 , 1 , 1 ] ] ; document . write ( maxPerimeter ( A ) ) ;

Index/key variables: i, j
Accumulator variables: i, sum
Iterator variables: i, j, k
Javascript program:
function maxScore ( money , beg , ed ) { let totalTurns = money . length ; let turnsTillNow = beg + ( ( totalTurns - 1 ) - ed ) ; if ( beg == ed ) { if ( turnsTillNow % 2 == 0 ) return [ money [ beg ] , " " ] ; else return [ 0 , " " ] ; } let scoreOne = maxScore ( money , beg + 1 , ed ) ; let scoreTwo = maxScore ( money , beg , ed - 1 ) ; if ( turnsTillNow % 2 == 0 ) { if ( money [ beg ] + scoreOne [ 0 ] > money [ ed ] + scoreTwo [ 0 ] ) { return [ money [ beg ] + scoreOne [ 0 ] , " " + scoreOne [ 1 ] ] ; } else return [ money [ ed ] + scoreTwo [ [ 0 ] ] , " " + scoreTwo [ 1 ] ] ; } else { if ( scoreOne . first < scoreTwo . first ) return [ scoreOne [ 0 ] , " " + scoreOne [ 1 ] ] ; else return [ scoreTwo [ 0 ] , " " + scoreTwo [ 1 ] ] ; } } let ar = [ 10 , 80 , 90 , 30 ] ; let arraySize = ar . length ; let bags = ar ; let ans = maxScore ( bags , 0 , bags . length - 1 ) ; document . write ( ans [ 0 ] + " " + ans [ 1 ] + " " ) ;

Index/key variables: beg, ed
Javascript program:
const MAX = 1000000000 ; function minJumps ( arr , N ) { let fib = new Array ( 30 ) ; fib [ 0 ] = 0 ; fib [ 1 ] = 1 ; for ( let i = 2 ; i < 30 ; i ++ ) fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; let DP = new Array ( N + 2 ) ; DP [ 0 ] = 0 ; for ( let i = 1 ; i <= N + 1 ; i ++ ) DP [ i ] = MAX ; for ( let i = 1 ; i <= N + 1 ; i ++ ) { for ( let j = 1 ; j < 30 ; j ++ ) { if ( ( arr [ i - 1 ] == 1 i == N + 1 ) && i - fib [ j ] >= 0 ) DP [ i ] = Math . min ( DP [ i ] , 1 + DP [ i - fib [ j ] ] ) ; } } if ( DP [ N + 1 ] != MAX ) return DP [ N + 1 ] ; else return - 1 ; } let arr = [ 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 0 , 0 ] ; let n = arr . length ; document . write ( minJumps ( arr , n ) ) ;

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