dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
class Process { constructor ( pid , bt , art ) { } } function findWaitingTime ( proc , n , wt ) { let rt = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) rt [ i ] = proc [ i ] . bt ; let complete = 0 , t = 0 , minm = Number . MAX_VALUE ; let shortest = 0 , finish_time ; let check = false ; while ( complete != n ) { for ( let j = 0 ; j < n ; j ++ ) { if ( ( proc [ j ] . art <= t ) && ( rt [ j ] < minm ) && rt [ j ] > 0 ) { minm = rt [ j ] ; shortest = j ; check = true ; } } if ( check == false ) { t ++ ; continue ; } rt [ shortest ] -- ; minm = rt [ shortest ] ; if ( minm == 0 ) minm = Number . MAX_VALUE ; if ( rt [ shortest ] == 0 ) { complete ++ ; check = false ; finish_time = t + 1 ; wt [ shortest ] = finish_time - proc [ shortest ] . bt - proc [ shortest ] . art ; if ( wt [ shortest ] < 0 ) wt [ shortest ] = 0 ; } t ++ ; } } function findTurnAroundTime ( proc , n , wt , tat ) { for ( let i = 0 ; i < n ; i ++ ) tat [ i ] = proc [ i ] . bt + wt [ i ] ; } function findavgTime ( proc , n ) { let wt = new Array ( n ) , tat = new Array ( n ) ; let total_wt = 0 , total_tat = 0 ; findWaitingTime ( proc , n , wt ) ; findTurnAroundTime ( proc , n , wt , tat ) ; document . write ( " " + " " + " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) { total_wt = total_wt + wt [ i ] ; total_tat = total_tat + tat [ i ] ; document . write ( " " + proc [ i ] . pid + " " + proc [ i ] . bt + " " + wt [ i ] + " " + tat [ i ] + " " ) ; } document . write ( " " + total_wt / n + " " ) ; document . write ( " " + total_tat / n + " " ) ; } let proc = [ new Process ( 1 , 6 , 1 ) , new Process ( 2 , 8 , 1 ) , new Process ( 3 , 7 , 2 ) , new Process ( 4 , 3 , 3 ) ] ; findavgTime ( proc , proc . length ) ;

Index/key variables: i, j, shortest
Accumulator variables: complete, i, j, t
Iterator variables: i, j
Boolean variables: check
Class/struct names: Process
Javascript program:
let MAX = 100001 function minimumDeletions ( A , N ) { let dp = new Array ( N ) . fill ( 0 ) . map ( ( ) => new Array ( MAX ) ) ; for ( let i = 0 ; i < N ; i ++ ) for ( let j = 0 ; j < MAX ; j ++ ) dp [ i ] [ j ] = 0 ; for ( let i = 0 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = 1 ; for ( let j = i - 1 ; j >= 0 ; j -- ) { if ( A [ i ] >= A [ j ] ) { let diff = A [ i ] - A [ j ] ; for ( let k = 0 ; k <= diff ; k ++ ) { dp [ i ] = Math . max ( dp [ i ] , dp [ j ] [ k ] + 1 ) ; } } } } let maxSetSize = - 1 ; for ( let i = 0 ; i < MAX ; i ++ ) maxSetSize = Math . max ( maxSetSize , dp [ N - 1 ] [ i ] ) ; return N - maxSetSize ; } let A = [ 1 , 4 , 5 , 7 , 20 , 21 ] ; let N = A . length ; document . write ( minimumDeletions ( A , N ) + " " ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
let dp = [ ] ; for ( let i = 0 ; i < 1005 ; i ++ ) { dp [ i ] = [ ] ; for ( let j = 0 ; j < 9005 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } let mod = 1000000007 ; function check ( sum , x , y ) { while ( sum > 0 ) { let ln = sum % 10 ; if ( ln != x && ln != y ) { return 0 ; } sum = Math . floor ( sum / 10 ) ; } return 1 ; } function countNumbers ( n , x , y , sum ) { for ( let i = 0 ; i < 1005 ; i ++ ) { for ( let j = 0 ; j < 9005 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } if ( n == 0 ) { return check ( sum , x , y ) ; } if ( dp [ n ] [ sum ] != - 1 ) { return dp [ n ] [ sum ] % mod ; } let option1 = countNumbers ( n - 1 , x , y , sum + x ) % mod ; let option2 = countNumbers ( n - 1 , x , y , sum + y ) % mod ; return dp [ n ] [ sum ] = ( option1 + option2 ) % mod ; } let N = 3 , X = 1 , Y = 5 ; document . write ( countNumbers ( N , X , Y , 0 ) % mod ) ;

Index/key variables: i, j, n, sum
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function check ( mask , i ) { var c = ( mask & ( 1 << i ) ) ; return c != 0 ; } function solve ( a , s , n , prev , mask , dp ) { if ( mask == 0 ) return 0 ; if ( dp [ mask ] [ prev + 1 ] != - 1 ) return dp [ mask ] [ prev + 1 ] ; var ans = 10000 ; for ( var i = 0 ; i < s . length ; i ++ ) { var id = s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; if ( check ( mask , id ) ) { if ( prev == - 1 ) { ans = Math . min ( ans , solve ( a , s , n , id , mask ^ ( 1 << id ) , dp ) ) ; } else { ans = Math . min ( ans , a [ prev ] [ id ] + solve ( a , s , n , id , mask ^ ( 1 << id ) , dp ) ) ; } } } dp [ mask ] [ prev + 1 ] = ans ; return ans ; } function generatePermutation ( mask , n , a , s ) { var dp = Array . from ( Array ( ( 1 << n ) + 5 ) , ( ) => Array ( n + 5 ) . fill ( - 1 ) ) ; for ( var i = 0 ; i < s . length ; i ++ ) { var id = s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; mask |= ( 1 << id ) ; } document . write ( solve ( a , s , n , - 1 , mask , dp ) + " " ) ; } var N = 5 ; var str = " " ; var mat = [ [ 0 , 5 , 1 , 5 , 3 ] , [ 4 , 0 , 9 , 4 , 2 ] , [ 7 , 9 , 0 , 10 , 7 ] , [ 1 , 2 , 8 , 0 , 2 ] , [ 3 , 9 , 7 , 7 , 0 ] ] ; generatePermutation ( 0 , N , mat , str ) ;

Index/key variables: i, id, mask, prev
Accumulator variables: i, mask
Iterator variables: i
Javascript program:
var inf = 10000000 ; function preprocess ( a , n ) { var p = Array ( n ) ; p [ 0 ] = a [ 0 ] ; for ( var i = 1 ; i < n ; i ++ ) { p [ i ] = p [ i - 1 ] + a [ i ] ; } return p ; } function Combine ( p , i , j ) { if ( i == 0 ) return p [ j ] ; else return p [ j ] - p [ i - 1 ] ; } function minCost ( a , i , j , k , prefix , dp ) { if ( i >= j ) return 0 ; if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ; var best_cost = inf ; for ( var pos = i ; pos < j ; pos ++ ) { var left = minCost ( a , i , pos , k , prefix , dp ) ; var right = minCost ( a , pos + 1 , j , k , prefix , dp ) ; best_cost = Math . min ( best_cost , left + right + ( k * Combine ( prefix , i , j ) ) ) ; } return dp [ i ] [ j ] = best_cost ; } var n = 4 ; var a = [ 4 , 5 , 6 , 7 ] ; var k = 3 ; var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( n + 1 ) . fill ( - 1 ) ) ; var prefix = preprocess ( a , n ) ; document . write ( minCost ( a , 0 , n - 1 , k , prefix , dp ) )

Index/key variables: i, j
Accumulator variables: i, pos
Iterator variables: i, pos
Javascript program:
function minOperations ( n ) { let dp = new Array ( n + 1 ) ; dp [ 1 ] = 0 ; for ( let i = 2 ; i <= n ; i ++ ) { dp [ i ] = Number . MAX_VALUE ; if ( i % 2 == 0 ) { let x = dp [ parseInt ( i / 2 , 10 ) ] ; if ( x + 1 < dp [ i ] ) { dp [ i ] = x + 1 ; } } if ( i % 3 == 0 ) { let x = dp [ parseInt ( i / 3 , 10 ) ] ; if ( x + 1 < dp [ i ] ) { dp [ i ] = x + 1 ; } } let x = dp [ i - 1 ] ; if ( x + 1 < dp [ i ] ) { dp [ i ] = x + 1 ; } } return dp [ n ] ; } let n = 15 ; document . write ( minOperations ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function ReverseBitonic ( arr , N ) { let i , j ; let lds = [ ] ; 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 ; } } } let lis = [ ] ; for ( i = 0 ; i < N ; i ++ ) { lis [ i ] = 1 ; } for ( i = N - 2 ; i >= 0 ; i -- ) { for ( j = N - 1 ; j > i ; j -- ) { if ( arr [ i ] < arr [ j ] && lis [ i ] < lis [ j ] + 1 ) { lis [ i ] = lis [ j ] + 1 ; } } } let max = lis [ 0 ] + lds [ 0 ] - 1 ; for ( i = 1 ; i < N ; i ++ ) { if ( lis [ i ] + lds [ i ] - 1 > max ) { max = lis [ i ] + lds [ i ] - 1 ; } } return max ; } let arr = [ 0 , 8 , 4 , 12 , 2 , 10 , 6 , 14 , 1 , 9 , 5 , 13 , 3 , 11 , 7 , 15 ] ; let N = arr . length ; document . write ( " " + ReverseBitonic ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findPath ( maze , xpos , ypos , key ) { if ( xpos < 0 xpos >= maze . length ypos < 0 ypos >= maze . length ) return false ; if ( maze [ xpos ] [ ypos ] == ' ' ) { if ( key == true ) if ( xpos == maze . length - 1 && ypos == maze . length - 1 ) return true ; return findPath ( maze , xpos + 1 , ypos , false ) || findPath ( maze , xpos , ypos + 1 , false ) ; return false ; } if ( xpos == maze . length - 1 && ypos == maze . length - 1 ) return true ; return findPath ( maze , xpos + 1 , ypos , key ) || findPath ( maze , xpos , ypos + 1 , key ) ; } function mazeProb ( maze , xpos , ypos ) { let key = true ; if ( findPath ( maze , xpos , ypos , key ) ) return true ; return false ; } let maze = [ [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] ] ; let n = maze . length ; if ( mazeProb ( maze , 0 , 0 ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: xpos, ypos
Boolean variables: key
Javascript program:
function FindMinimumCost ( ind , a , n , k , dp ) { if ( ind == ( n - 1 ) ) return 0 ; else if ( dp [ ind ] != - 1 ) return dp [ ind ] ; else { var ans = Number . MAX_VALUE ; for ( var i = 1 ; i <= k ; i ++ ) { if ( ind + i < n ) ans = Math . min ( ans , Math . abs ( a [ ind + i ] - a [ ind ] ) + FindMinimumCost ( ind + i , a , n , k , dp ) ) ; else break ; } return dp [ ind ] = ans ; } } var a = [ 10 , 30 , 40 , 50 , 20 ] ; var k = 3 ; var n = a . length ; var dp = Array ( n ) . fill ( - 1 ) ; document . write ( FindMinimumCost ( 0 , a , n , k , dp ) ) ;

Index/key variables: ind
Accumulator variables: i
Iterator variables: i
Javascript program:
var MAX = 100000 ; prefix = Array ( MAX ) . fill ( 0 ) ; function sieve_modified ( ) { for ( var i = 2 ; i < MAX ; i += 2 ) { for ( var j = i ; j < MAX ; j += i ) prefix [ j ] += i ; } for ( var i = 1 ; i < MAX ; i ++ ) prefix [ i ] += prefix [ i - 1 ] ; } function sumEvenFactors ( L , R ) { return ( prefix [ R ] - prefix [ L - 1 ] ) ; } sieve_modified ( ) ; var l = 6 , r = 10 ; document . write ( sumEvenFactors ( l , r ) ) ;

Index/key variables: R, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var M = 20 ; var dp = Array . from ( Array ( M ) , ( ) => Array ( 165 ) ) ; var n , m ; function count ( pos , sum , rem , tight , nonz , num ) { if ( pos == num . length ) { if ( rem == 0 && sum == n ) return 1 ; return 0 ; } if ( dp [ pos ] [ sum ] [ rem ] [ tight ] != - 1 ) return dp [ pos ] [ sum ] [ rem ] [ tight ] ; var ans = 0 ; var limit = ( tight ? 9 : num [ pos ] ) ; for ( var d = 0 ; d <= limit ; d ++ ) { if ( d == 0 && nonz ) continue ; var currSum = sum + d ; var currRem = ( rem * 10 + d ) % m ; var currF = ( tight != 0 || ( d < num [ pos ] ) ) ? 1 : 0 ; ans += count ( pos + 1 , currSum , currRem , currF , ( nonz != 0 d != 0 ) ? 1 : 0 , num ) ; } dp [ pos ] [ sum ] [ rem ] [ tight ] = ans ; return ans ; } function solve ( x ) { var num = [ ] ; while ( x ) { num . push ( x % 10 ) ; x = parseInt ( x / 10 ) ; } num . reverse ( ) ; for ( var i = 0 ; i < M ; i ++ ) for ( var j = 0 ; j < 165 ; j ++ ) dp [ i ] [ j ] = Array . from ( Array ( M ) , ( ) => Array ( 2 ) . fill ( - 1 ) ) ; return count ( 0 , 0 , 0 , 0 , 0 , num ) ; } var L = 1 , R = 100 ; n = 8 , m = 2 ; document . write ( solve ( R ) - solve ( L ) ) ;

Index/key variables: i, j, pos, rem, sum, tight
Accumulator variables: ans, d, i, j
Iterator variables: d, i, j
Javascript program:
let M = 20 ; let dp = new Array ( M ) ; for ( let i = 0 ; i < M ; i ++ ) { dp [ i ] = new Array ( M ) ; for ( let j = 0 ; j < M ; j ++ ) { dp [ i ] [ j ] = new Array ( 2 ) ; for ( let k = 0 ; k < 2 ; k ++ ) dp [ i ] [ j ] [ k ] = 0 ; } } let K ; let num ; function countInRangeUtil ( pos , cnt , tight ) { if ( pos == num . length ) { if ( cnt <= K ) return 1 ; return 0 ; } if ( dp [ pos ] [ cnt ] [ tight ] != - 1 ) return dp [ pos ] [ cnt ] [ tight ] ; let ans = 0 ; let limit = ( tight != 0 ? 9 : num [ pos ] ) ; for ( let dig = 0 ; dig <= limit ; dig ++ ) { let currCnt = cnt ; if ( dig != 0 ) currCnt ++ ; let currTight = tight ; if ( dig < num [ pos ] ) currTight = 1 ; ans += countInRangeUtil ( pos + 1 , currCnt , currTight ) ; } return dp [ pos ] [ cnt ] [ tight ] = ans ; } function countInRange ( x ) { num = [ ] ; while ( x != 0 ) { num . push ( x % 10 ) ; x = Math . floor ( x / 10 ) ; } num . reverse ( ) ; for ( let i = 0 ; i < M ; i ++ ) for ( let j = 0 ; j < M ; j ++ ) for ( let k = 0 ; k < 2 ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; return countInRangeUtil ( 0 , 0 , 0 ) ; } let L = 1 , R = 1000 ; K = 3 ; document . write ( ( countInRange ( R ) - countInRange ( L - 1 ) ) + " " ) ; L = 9995 ; R = 10005 ; K = 2 ; document . write ( ( countInRange ( R ) - countInRange ( L - 1 ) ) + " " ) ;

Index/key variables: cnt, i, j, k, pos, tight
Accumulator variables: ans, currCnt, dig, i, j, k
Iterator variables: dig, i, j, k
Javascript program:
let N = 1000 ; function find ( index , openbrk , n , dp , adj ) { if ( openbrk < 0 ) { return 0 ; } if ( index == n ) { if ( openbrk == 0 ) { return 1 ; } else { return 0 ; } } if ( dp [ index ] [ openbrk ] != - 1 ) { return dp [ index ] [ openbrk ] ; } if ( adj [ index ] == 1 ) { dp [ index ] [ openbrk ] = find ( index + 1 , openbrk + 1 , n , dp , adj ) ; } else { dp [ index ] [ openbrk ] = find ( index + 1 , openbrk + 1 , n , dp , adj ) + find ( index + 1 , openbrk - 1 , n , dp , adj ) ; } return dp [ index ] [ openbrk ] ; } let dp = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { dp [ i ] = new Array ( N ) ; for ( let j = 0 ; j < N ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } let n = 2 ; let adj = [ 1 , 0 , 0 , 0 ] ; document . write ( find ( 0 , 0 , 2 * n , dp , adj ) ) ;

Index/key variables: i, index, j, openbrk
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let ans = 0 ; function findMaxValUtil ( arr , n , num , maxLimit , ind ) { if ( ind == n ) { ans = Math . max ( ans , num ) ; return ; } if ( num - arr [ ind ] >= 0 ) { findMaxValUtil ( arr , n , num - arr [ ind ] , maxLimit , ind + 1 ) ; } if ( num + arr [ ind ] <= maxLimit ) { findMaxValUtil ( arr , n , num + arr [ ind ] , maxLimit , ind + 1 ) ; } } function findMaxVal ( arr , n , num , maxLimit ) { let ind = 0 ; findMaxValUtil ( arr , n , num , maxLimit , ind ) ; return ans ; } let num = 1 ; let arr = [ 3 , 10 , 6 , 4 , 5 ] ; let n = arr . length ; let maxLimit = 15 ; document . write ( findMaxVal ( arr , n , num , maxLimit ) ) ;

Index/key variables: ind
Javascript program:
function printSets ( set1 , set2 ) { var i ; for ( i = 0 ; i < set1 . length ; i ++ ) { document . write ( set1 [ i ] + " " ) ; } document . write ( " " ) ; for ( i = 0 ; i < set2 . length ; i ++ ) { document . write ( set2 [ i ] + " " ) ; } } function findSets ( arr , n , set1 , set2 , sum1 , sum2 , pos ) { if ( pos == n ) { if ( sum1 == sum2 ) { printSets ( set1 , set2 ) ; return true ; } else return false ; } set1 . push ( arr [ pos ] ) ; var res = findSets ( arr , n , set1 , set2 , sum1 + arr [ pos ] , sum2 , pos + 1 ) ; if ( res ) return res ; set1 . pop ( ) ; set2 . push ( arr [ pos ] ) ; res = findSets ( arr , n , set1 , set2 , sum1 , sum2 + arr [ pos ] , pos + 1 ) ; if ( res == false ) if ( ! set2 . length == 0 ) set2 . pop ( ) ; return res ; } function isPartitionPoss ( arr , n ) { var sum = 0 ; for ( var i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; var set1 = [ ] ; var set2 = [ ] ; return findSets ( arr , n , set1 , set2 , 0 , 0 , 0 ) ; } var arr = [ 5 , 5 , 1 , 11 ] ; var n = arr . length ; if ( ! isPartitionPoss ( arr , n ) ) { document . write ( " " ) ; }

Index/key variables: i, pos
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function maximumSumSubarray ( arr , n ) { let min_prefix_sum = 0 ; let res = Number . MIN_VALUE ; let prefix_sum = [ ] ; prefix_sum [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ; for ( let i = 0 ; i < n ; i ++ ) { res = Math . max ( res , prefix_sum [ i ] - min_prefix_sum ) ; min_prefix_sum = Math . min ( min_prefix_sum , prefix_sum [ i ] ) ; } return res ; } let arr1 = [ - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 ] ; let n1 = arr1 . length ; document . write ( maximumSumSubarray ( arr1 , n1 ) + " " ) ; let arr2 = [ 4 , - 8 , 9 , - 4 , 1 , - 8 , - 1 , 6 ] ; let n2 = arr2 . length ; document . write ( maximumSumSubarray ( arr2 , n2 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function sequence ( n ) { let i ; let f = [ ] ; f [ 0 ] = 0 ; f [ 1 ] = 1 ; f [ 2 ] = 1 ; for ( let i = 3 ; i <= n ; i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ; return f [ n ] ; } let n = 10 ; document . write ( sequence ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
of maximum product of an increasing function lis ( arr , n ) { let mpis = [ ] ; let max = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) mpis [ i ] = arr [ i ] ; for ( let i = 1 ; i < n ; i ++ ) for ( let j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ; for ( let k = 0 ; k < mpis . length ; k ++ ) { if ( mpis [ k ] > max ) { max = mpis [ k ] ; } } return max ; } let arr = [ 3 , 100 , 4 , 5 , 150 , 6 ] ; let n = arr . length ; document . write ( lis ( arr , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function Hosoya ( n , m ) { if ( ( n == 0 && m == 0 ) || ( n == 1 && m == 0 ) || ( n == 1 && m == 1 ) || ( n == 2 && m == 1 ) ) return 1 ; if ( n > m ) return Hosoya ( n - 1 , m ) + Hosoya ( n - 2 , m ) ; else if ( m == n ) return Hosoya ( n - 1 , m - 1 ) + Hosoya ( n - 2 , m - 2 ) ; else return 0 ; } function printHosoya ( n ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j <= i ; j ++ ) document . write ( Hosoya ( i , j ) + " " ) ; document . write ( " " ) ; } } let n = 5 ; printHosoya ( n ) ;

Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function largestSubset ( a , n ) { let dp = [ ] ; dp [ n - 1 ] = 1 ; for ( let i = n - 2 ; i >= 0 ; i -- ) { let mxm = 0 ; for ( let j = i + 1 ; j < n ; j ++ ) { if ( a [ j ] % a [ i ] == 0 a [ i ] % a [ j ] == 0 ) { mxm = Math . max ( mxm , dp [ j ] ) ; } } dp [ i ] = 1 + mxm ; } return Math . max ( ... dp ) ; } let a = [ 1 , 3 , 6 , 13 , 17 , 18 ] ; let n = a . length ; document . write ( largestSubset ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let dp = new Array ( MAXN ) ; function solve ( n ) { if ( n < 0 ) return 0 ; if ( n == 0 ) return 1 ; if ( dp [ n ] != - 1 ) return dp [ n ] ; return dp [ n ] = solve ( n - 1 ) + solve ( n - 3 ) + solve ( n - 5 ) ; }

Index/key variables: n
Javascript program:
function countFriendsPairings ( n ) { let dp = [ ] ; for ( let i = 0 ; i <= n ; i ++ ) { if ( i <= 2 ) dp [ i ] = i ; else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ; } return dp [ n ] ; } let n = 4 ; document . write ( countFriendsPairings ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function countFriendsPairings ( n ) { let a = 1 , b = 2 , c = 0 ; if ( n <= 2 ) { return n ; } for ( let i = 3 ; i <= n ; i ++ ) { c = b + ( i - 1 ) * a ; a = b ; b = c ; } return c ; } let n = 4 ; document . write ( countFriendsPairings ( n ) ) ;

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

Index/key variables: i, j, k, m, n, o
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function printShortestSuperSeq ( X , Y ) { let m = X . length ; let n = Y . length ; let dp = new Array ( m + 1 ) ; for ( let i = 0 ; i < ( m + 1 ) ; i ++ ) { dp [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < ( n + 1 ) ; j ++ ) dp [ i ] [ j ] = 0 ; } for ( let i = 0 ; i <= m ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { if ( i == 0 ) { dp [ i ] [ j ] = j ; } else if ( j == 0 ) { dp [ i ] [ j ] = i ; } else if ( X [ i - 1 ] == Y [ j - 1 ] ) { dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; } else { dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } } let str = " " ; let i = m , j = n ; while ( i > 0 && j > 0 ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { str += ( X [ i - 1 ] ) ; i -- ; j -- ; } else if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j - 1 ] ) { str += ( Y [ j - 1 ] ) ; j -- ; } else { str += ( X [ i - 1 ] ) ; i -- ; } } while ( i > 0 ) { str += ( X [ i - 1 ] ) ; i -- ; } while ( j > 0 ) { str += ( Y [ j - 1 ] ) ; j -- ; } str = reverse ( str ) ; return str ; } function reverse ( input ) { let temparray = input . split ( " " ) ; let left , right = 0 ; right = temparray . length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { let temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return ( temparray ) . join ( " " ) ; } let X = " " ; let Y = " " ; document . write ( printShortestSuperSeq ( X , Y ) ) ;

Index/key variables: i, j, left, right
Accumulator variables: i, j, left, right, str
Iterator variables: i, j, left
Javascript program:
function findLongestRepeatingSubSeq ( str ) { var n = str . length ; var dp = new Array ( n + 1 ) ; for ( var i = 0 ; i <= n ; i ++ ) { dp [ i ] = new Array ( n + 1 ) ; for ( var j = 0 ; j <= n ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 1 ; j <= n ; j ++ ) { if ( ( str [ i - 1 ] == str [ j - 1 ] ) && ( i != j ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ; } } return dp [ n ] [ n ] ; } var str = " " ; document . write ( " " + findLongestRepeatingSubSeq ( str ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let lookup = new Array ( 50 ) ; for ( let i = 0 ; i < 50 ; i ++ ) { lookup [ i ] = new Array ( 1000 ) ; for ( let j = 0 ; j < 1000 ; j ++ ) { lookup [ i ] [ j ] = new Array ( 1000 ) ; for ( let k = 0 ; k < 1000 ; k ++ ) { lookup [ i ] [ j ] [ k ] = new Array ( 2 ) ; } } } function countRec ( digits , esum , osum , isOdd , n ) { if ( digits == n ) return ( esum - osum == 1 ) ? 1 : 0 ; if ( lookup [ digits ] [ esum ] [ osum ] [ isOdd ] != - 1 ) return lookup [ digits ] [ esum ] [ osum ] [ isOdd ] ; let ans = 0 ; if ( isOdd == 1 ) for ( let i = 0 ; i <= 9 ; i ++ ) ans += countRec ( digits + 1 , esum , osum + i , 0 , n ) ; for ( let i = 0 ; i <= 9 ; i ++ ) ans += countRec ( digits + 1 , esum + i , osum , 1 , n ) ; return lookup [ digits ] [ esum ] [ osum ] [ isOdd ] = ans ; } function finalCount ( n ) { let digits = 0 ; for ( let i = 0 ; i < 50 ; i ++ ) for ( let j = 0 ; j < 1000 ; j ++ ) for ( let k = 0 ; k < 1000 ; k ++ ) for ( let l = 0 ; l < 2 ; l ++ ) lookup [ i ] [ j ] [ k ] [ l ] = - 1 ; let ans = 0 ; let esum = 0 , osum = 0 ; for ( let i = 1 ; i <= 9 ; i ++ ) ans += countRec ( digits + 1 , esum + i , osum , 1 , n ) ; return ans ; } let n = 3 ; document . write ( " " + n + " " + finalCount ( n ) ) ;

Index/key variables: digits, esum, i, isOdd, j, k, l, osum
Accumulator variables: ans, i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
function numberOfPaths ( m , n ) { dp = Array . from ( { length : n } , ( _ , i ) => 0 ) ; dp [ 0 ] = 1 ; for ( i = 0 ; i < m ; i ++ ) { for ( j = 1 ; j < n ; j ++ ) { dp [ j ] += dp [ j - 1 ] ; } } return dp [ n - 1 ] ; } document . write ( numberOfPaths ( 3 , 3 ) ) ;

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