dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function binaryStrings ( N ) { var dp = Array ( N + 1 ) . fill ( 0 ) ; dp [ 0 ] = 0 ; dp [ 1 ] = 0 ; var power = Array ( N + 1 ) . fill ( 0 ) ; power [ 0 ] = 1 ; for ( i = 1 ; i <= N ; i ++ ) { power [ i ] = 2 * power [ i - 1 ] ; } for ( i = 2 ; i <= N ; i ++ ) { dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + power [ i - 2 ] ; } document . write ( dp [ N ] ) ; } var N = 12 ; binaryStrings ( N ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function kadane ( v ) { let currSum = 0 ; let maxSum = Number . MIN_VALUE ; for ( let i = 0 ; i < v . length ; i ++ ) { currSum += v [ i ] ; if ( currSum > maxSum ) { maxSum = currSum ; } if ( currSum < 0 ) { currSum = 0 ; } } return maxSum ; } function maxSubmatrixSum ( A ) { let r = A . length ; let c = A [ 0 ] . length ; let prefix = new Array ( r ) ; for ( let i = 0 ; i < r ; i ++ ) { prefix [ i ] = new Array ( c ) ; for ( let j = 0 ; j < c ; j ++ ) { prefix [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < r ; i ++ ) { for ( let j = 0 ; j < c ; j ++ ) { if ( j == 0 ) prefix [ i ] [ j ] = A [ i ] [ j ] ; else prefix [ i ] [ j ] = A [ i ] [ j ] + prefix [ i ] [ j - 1 ] ; } } let maxSum = Number . MIN_VALUE ; for ( let i = 0 ; i < c ; i ++ ) { for ( let j = i ; j < c ; j ++ ) { let v = [ ] ; for ( let k = 0 ; k < r ; k ++ ) { let el = 0 ; if ( i == 0 ) el = prefix [ k ] [ j ] ; else el = prefix [ k ] [ j ] - prefix [ k ] [ i - 1 ] ; v . push ( el ) ; } maxSum = Math . max ( maxSum , kadane ( v ) ) ; } } document . write ( maxSum + " " ) ; } let matrix = [ [ 0 , - 2 , - 7 , 0 ] , [ 9 , 2 , - 6 , 2 ] , [ - 4 , 1 , - 4 , 1 ] , [ - 1 , 8 , 0 , - 2 ] ] ; maxSubmatrixSum ( matrix ) ;

Index/key variables: i, j, k
Accumulator variables: currSum, i, j, k
Iterator variables: i, j, k
Javascript program:
function minCost ( costs , N ) { if ( N == 0 ) return 0 ; let dp = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { dp [ i ] = new Array ( 3 ) ; for ( let j = 0 ; j < 3 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } dp [ 0 ] [ 0 ] = costs [ 0 ] [ 0 ] ; dp [ 0 ] [ 1 ] = costs [ 0 ] [ 1 ] ; dp [ 0 ] [ 2 ] = costs [ 0 ] [ 2 ] ; for ( let i = 1 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = Math . min ( dp [ i - 1 ] [ 1 ] , dp [ i - 1 ] [ 2 ] ) + costs [ i ] [ 0 ] ; dp [ i ] [ 1 ] = Math . min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 2 ] ) + costs [ i ] [ 1 ] ; dp [ i ] [ 2 ] = Math . min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + costs [ i ] [ 2 ] ; } document . write ( Math . min ( dp [ N - 1 ] [ 0 ] , Math . min ( dp [ N - 1 ] [ 1 ] , dp [ N - 1 ] [ 2 ] ) ) ) ; } let costs = [ [ 14 , 2 , 11 ] , [ 11 , 14 , 5 ] , [ 14 , 3 , 10 ] ] ; let N = costs . length ; minCost ( costs , N ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let dp = [ ] ; for ( var i = 0 ; i < 2001 ; i ++ ) { dp [ i ] = [ ] ; for ( var j = 0 ; j < 2001 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } function solve ( A , i , sum , N ) { let res = 2001 ; if ( sum < 0 || ( i == N && sum != 0 ) ) { return 2001 ; } if ( sum == 0 i >= N ) { dp [ i ] [ sum ] = 0 ; return dp [ i ] [ sum ] ; } if ( dp [ i ] [ sum ] != - 1 ) { return dp [ i ] [ sum ] ; } res = Math . min ( solve ( A , i + 1 , sum - A [ i ] , N ) + 1 , solve ( A , i + 1 , sum , N ) ) ; dp [ i ] [ sum ] = res ; return dp [ i ] [ sum ] ; } function minOp ( A , N ) { let sum = 0 ; for ( let i = 0 ; i < A . length ; i ++ ) { sum += A [ i ] ; } if ( sum % 2 == 0 ) { let dp = [ ] ; for ( var i = 0 ; i < 2001 ; i ++ ) { dp [ i ] = [ ] ; for ( var j = 0 ; j < 2001 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } let ans = solve ( A , 0 , Math . floor ( sum / 2 ) , N ) ; if ( ans < 0 ans > N ) { document . write ( " " ) ; } else { document . write ( ans , " " ) ; } } else { document . write ( " " ) ; } } let A = [ 2 , 3 , 1 , 4 ] ; let N = A . length ; minOp ( A , N ) ;

Index/key variables: i, j, sum
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
var dp = Array . from ( Array ( 101 ) , ( ) => Array ( 101 ) ) ; for ( var i = 0 ; i < 101 ; i ++ ) for ( var j = 0 ; j < 101 ; j ++ ) dp [ i ] [ j ] = new Array ( 1001 ) . fill ( 0 ) ; function countAverage ( n , K , arr ) { dp [ 0 ] [ 0 ] [ 0 ] = 1 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var k = 0 ; k < n ; k ++ ) { for ( var s = 0 ; s <= 1000 ; s ++ ) { dp [ i + 1 ] [ k + 1 ] [ s + arr [ i ] ] += dp [ i ] [ k ] [ s ] ; dp [ i + 1 ] [ k ] [ s ] += dp [ i ] [ k ] [ s ] ; } } } var cnt = 0 ; for ( var j = 1 ; j <= n ; j ++ ) { cnt += dp [ n ] [ j ] [ K * j ] ; } return cnt ; } var arr = [ 9 , 7 , 8 , 9 ] ; var K = 8 ; var N = arr . length document . write ( countAverage ( N , K , arr ) ) ;

Index/key variables: i, j, k, n, s
Accumulator variables: cnt, i, j, k, s
Iterator variables: i, j, k, s
Javascript program:
function numberofpairs ( v , k ) { let n = v . length ; if ( n % 2 == 1 ) { document . write ( 0 ) ; return ; } let ans = 0 ; let dp = new Array ( k ) ; for ( let i = 0 ; i < k ; i ++ ) { dp [ i ] = new Array ( 2 ) ; for ( let j = 0 ; j < 2 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( ( i + j ) % 2 == 0 ) dp [ v [ i ] [ j ] - 1 ] [ 0 ] ++ ; else dp [ v [ i ] [ j ] - 1 ] [ 1 ] ++ ; } } for ( let i = 0 ; i < k ; i ++ ) { for ( let j = i + 1 ; j < k ; j ++ ) { ans += dp [ i ] [ 0 ] * dp [ j ] [ 1 ] ; ans += dp [ i ] [ 1 ] * dp [ j ] [ 0 ] ; } } document . write ( ans + " " ) ; } let mat = [ [ 1 , 2 ] , [ 3 , 4 ] ] ; let K = 4 ; numberofpairs ( mat , K ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
let dp = new Array ( 50 ) ; function FindMaxS ( X , Y , Z , n , A , B , C ) { if ( X < 0 Y < 0 Z < 0 ) return Number . MIN_VALUE ; if ( n < 0 ) return 0 ; if ( dp [ n ] [ X ] [ Y ] [ Z ] != - 1 ) { return dp [ n ] [ X ] [ Y ] [ Z ] ; } let ch = A [ n ] + FindMaxS ( X - 1 , Y , Z , n - 1 , A , B , C ) ; let ca = B [ n ] + FindMaxS ( X , Y - 1 , Z , n - 1 , A , B , C ) ; let co = C [ n ] + FindMaxS ( X , Y , Z - 1 , n - 1 , A , B , C ) ; let no = FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ; let maximum = Math . max ( ch , Math . max ( ca , Math . max ( co , no ) ) ) ; dp [ n ] [ X ] [ Y ] [ Z ] = maximum ; return dp [ n ] [ X ] [ Y ] [ Z ] ; } let X = 1 ; let Y = 1 ; let Z = 1 ; let A = [ 10 , 0 , 5 ] ; let B = [ 5 , 10 , 0 ] ; let C = [ 0 , 5 , 10 ] ; let n = B . length ; for ( let i = 0 ; i < 50 ; i ++ ) { dp [ i ] = new Array ( 50 ) ; for ( let j = 0 ; j < 50 ; j ++ ) { dp [ i ] [ j ] = new Array ( 50 ) ; for ( let k = 0 ; k < 50 ; k ++ ) { dp [ i ] [ j ] [ k ] = new Array ( 50 ) ; for ( let l = 0 ; l < 50 ; l ++ ) { dp [ i ] [ j ] [ k ] [ l ] = - 1 ; } } } } document . write ( FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ) ;

Index/key variables: X, Y, Z, i, j, k, l, n
Accumulator variables: i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
let MOD = 1000000007 ; let MEM = [ 1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512 , 1024 , 2048 , 4096 ] ; function mod_pow2 ( n ) { while ( n >= MEM . length ) MEM . push ( ( MEM [ MEM . length - 1 ] * 2 ) % MOD ) ; return MEM [ n ] ; } function inversions ( bstr ) { let total = 0 , zeros = 0 , questions = 0 ; bstr . reverse ( ) ; for ( let i = 0 ; i < bstr . length ; i ++ ) { let q ; if ( bstr [ i ] == ' ' ) { let z = zeros * mod_pow2 ( questions ) ; if ( questions == 0 ) q = 0 ; else q = questions * mod_pow2 ( questions - 1 ) ; total = ( total + z + q ) % MOD ; } else if ( bstr [ i ] == ' ' ) { zeros += 1 ; } else { total *= 2 ; let z = zeros * mod_pow2 ( questions ) ; if ( questions == 0 ) q = 0 ; else q = questions * mod_pow2 ( questions - 1 ) ; total = ( total + z + q ) % MOD ; questions += 1 ; } } return total ; } let S = " " . split ( ' ' ) ; document . write ( inversions ( S ) ) ;

Index/key variables: i, n
Accumulator variables: i, questions, total, zeros
Iterator variables: i
Javascript program:
function minRemovalsUtil ( arr , n ) { var result = 0 ; if ( n < 3 ) { return - 1 ; } var leftIncreasing = Array ( n ) . fill ( 0 ) ; var rightIncreasing = Array ( n ) . fill ( 0 ) ; for ( var i = 1 ; i < n ; i ++ ) { for ( var j = 0 ; j < i ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { leftIncreasing [ i ] = Math . max ( leftIncreasing [ i ] , leftIncreasing [ j ] + 1 ) ; } } } for ( var i = n - 2 ; i >= 0 ; i -- ) { for ( var j = n - 1 ; j > i ; j -- ) { if ( arr [ j ] < arr [ i ] ) { rightIncreasing [ i ] = Math . max ( rightIncreasing [ i ] , rightIncreasing [ j ] + 1 ) ; } } } for ( var i = 0 ; i < n ; i ++ ) { if ( leftIncreasing [ i ] != 0 && rightIncreasing [ i ] != 0 ) { result = Math . max ( result , leftIncreasing [ i ] + rightIncreasing [ i ] ) ; } } return n - ( result + 1 ) ; } function minRemovals ( arr , n ) { var ans = minRemovalsUtil ( arr , n ) ; document . write ( ans ) ; } var arr = [ 2 , 1 , 1 , 5 , 6 , 2 , 3 , 1 ] ; var n = arr . length ; minRemovals ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function cntNum ( X , i , sum , tight ) { if ( i >= X . length sum < 0 ) { if ( sum == 0 ) { return 1 ; } return 0 ; } var res = 0 ; var end = tight != 0 ? X [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) : 9 ; for ( var j = 0 ; j <= end ; j ++ ) { res += cntNum ( X , i + 1 , sum - j , ( tight > 0 & ( j == end ) ) == true ? 1 : 0 ) ; } return res ; } function UtilCntNumRange ( L , R , Y ) { if ( R == 0 && Y == 0 ) { return 1 ; } var str = ( R ) . toString ( ) ; var cntR = cntNum ( str , 0 , Y , 1 ) ; str = ( L - 1 ) . toString ( ) ; var cntL = cntNum ( str , 0 , Y , 1 ) ; return ( cntR - cntL ) ; } var L = 20 , R = 10000 , Y = 14 ; document . write ( UtilCntNumRange ( L , R , Y ) ) ;

Index/key variables: i
Accumulator variables: j, res
Iterator variables: j
Javascript program:
function bfs ( n , a , invGr , ans , parity ) { var q = [ ] ; var vis = Array ( n + 1 ) . fill ( 0 ) ; var dist = Array ( n + 1 ) . fill ( 0 ) ; for ( var i = 1 ; i <= n ; i ++ ) { if ( ( a [ i ] + parity ) & 1 ) { q . push ( i ) ; vis [ i ] = 1 ; } } while ( q . length != 0 ) { var v = q [ 0 ] ; q . shift ( ) ; invGr [ v ] . forEach ( u => { if ( ! vis [ u ] ) { dist [ u ] = dist [ v ] + 1 ; vis [ u ] = 1 ; if ( ( a [ u ] + parity ) % 2 == 0 ) { if ( ans [ u ] == - 1 ) ans [ u ] = dist [ u ] ; } q . push ( u ) ; } } ) ; } return ans ; } function minJumps ( a , jump , n ) { var invGr = Array . from ( Array ( n + 1 ) , ( ) => Array ( ) ) var ans = Array ( n + 1 ) . fill ( - 1 ) ; for ( var i = 1 ; i <= n ; i ++ ) { [ i + jump [ i ] , i - jump [ i ] ] . forEach ( ind => { if ( ind >= 1 && ind <= n ) { invGr [ ind ] . push ( i ) ; } } ) ; } ans = bfs ( n , a , invGr , ans , 0 ) ; ans = bfs ( n , a , invGr , ans , 1 ) ; for ( var i = 1 ; i <= n ; i ++ ) { document . write ( ans [ i ] + ' ' ) ; } } var arr = [ 0 , 4 , 2 , 5 , 2 , 1 ] ; var jump = [ 0 , 1 , 2 , 3 , 1 , 2 ] ; var N = arr . length ; minJumps ( arr , jump , N - 1 ) ;

Index/key variables: i, ind, u, v
Accumulator variables: i
Iterator variables: i
Javascript program:
function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } function findMaxGCD ( arr , N ) { var high = 0 ; for ( i = 0 ; i < N ; i ++ ) { high = Math . max ( high , arr [ i ] ) ; } var count = Array ( high + 1 ) . fill ( 0 ) ; for ( i = 0 ; i < N ; i ++ ) { count [ arr [ i ] ] += 1 ; } var counter = 0 ; for ( i = high ; i > 0 ; i -- ) { var j = i ; while ( j <= high ) { if ( count [ j ] > 0 ) counter += count [ j ] ; j += i ; if ( counter == 2 ) return i ; } counter = 0 ; } return 0 ; } function maxlen ( i , j , arr , arr1 , N , maxgcd ) { var a = 1 ; if ( i >= N j >= N ) return 0 ; if ( __gcd ( arr [ i ] , arr1 [ j ] ) == maxgcd && arr [ i ] != arr1 [ j ] ) { a = Math . max ( a , 1 + maxlen ( i , j + 1 , arr , arr1 , N , maxgcd ) ) ; return a ; } return Math . max ( maxlen ( i + 1 , j , arr , arr1 , N , maxgcd ) , maxlen ( i , j + 1 , arr , arr1 , N , maxgcd ) ) ; } var arr = [ 1 , 2 , 8 , 5 , 6 ] ; var arr1 = [ 1 , 2 , 8 , 5 , 6 ] ; var n = arr . length ; arr . sort ( ) ; var maxgcd = findMaxGCD ( arr , n ) ; document . write ( maxlen ( 0 , 0 , arr , arr1 , n , maxgcd ) ) ;

Index/key variables: i, j
Accumulator variables: counter, i, j
Iterator variables: i
Javascript program:
let dp = [ ] ; let countPaths = 0 ; function isPerfectSquare ( n ) { let sr = Math . sqrt ( n ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function countUniquePaths ( a , m , n , ans ) { dp [ 0 ] [ 0 ] . push ( a [ 0 ] [ 0 ] ) ; for ( let i = 1 ; i < m ; i ++ ) { a [ i ] [ 0 ] *= a [ i - 1 ] [ 0 ] ; dp [ i ] [ 0 ] . push ( a [ i ] [ 0 ] ) ; } for ( let i = 1 ; i < n ; i ++ ) { a [ 0 ] [ i ] *= a [ 0 ] [ i - 1 ] ; dp [ 0 ] [ i ] . push ( a [ 0 ] [ i ] ) ; } for ( let i = 1 ; i < m ; i ++ ) { for ( let j = 1 ; j < n ; j ++ ) { let top = dp [ i - 1 ] [ j ] ; let left = dp [ i ] [ j - 1 ] ; let curr = [ ] ; for ( let k = 0 ; k < top . length ; k ++ ) { curr . push ( top [ k ] * a [ i ] [ j ] ) ; } for ( let k = 0 ; k < left . length ; k ++ ) { curr . push ( left [ k ] * a [ i ] [ j ] ) ; } dp [ i ] [ j ] = curr ; } } for ( let i = 0 ; i < dp [ m - 1 ] [ n - 1 ] . length ; i ++ ) { if ( isPerfectSquare ( dp [ m - 1 ] [ n - 1 ] [ i ] ) ) { countPaths ++ ; } } } let M = 3 , N = 4 ; let mat = [ [ 1 , 2 , 3 , 1 ] , [ 3 , 1 , 2 , 4 ] , [ 2 , 3 , 1 , 1 ] ] ; for ( let i = 0 ; i < 105 ; i ++ ) { dp . push ( [ ] ) ; for ( let j = 0 ; j < 105 ; j ++ ) dp [ i ] . push ( [ ] ) ; } countUniquePaths ( mat , M , N , 1 ) ; document . write ( countPaths ) ;

Index/key variables: i, j, k
Accumulator variables: countPaths, i, j, k
Iterator variables: i, j, k
Javascript program:
var MAX = 100000 ; var dp = Array ( MAX + 1 ) ; var denomination = [ ] ; function countMinCoins ( n , C , m ) { if ( n == 0 ) { dp [ 0 ] = 0 ; return 0 ; } if ( dp [ n ] != - 1 ) return dp [ n ] ; var ret = 1000000000 ; for ( var i = 0 ; i < m ; i ++ ) { if ( C [ i ] <= n ) { var x = countMinCoins ( n - C [ i ] , C , m ) ; if ( x != 1000000000 ) ret = Math . min ( ret , 1 + x ) ; } } dp [ n ] = ret ; return ret ; } function findSolution ( n , C , m ) { if ( n == 0 ) { denomination . forEach ( it => { document . write ( it + ' ' ) ; } ) ; return ; } for ( var i = 0 ; i < m ; i ++ ) { if ( n - C [ i ] >= 0 && dp [ n - C [ i ] ] + 1 == dp [ n ] ) { denomination . push ( C [ i ] ) ; findSolution ( n - C [ i ] , C , m ) ; break ; } } } function countMinCoinsUtil ( X , C , N ) { dp = Array ( MAX + 1 ) . fill ( - 1 ) ; var isPossible = countMinCoins ( X , C , N ) ; if ( isPossible == 1000000000 ) { document . write ( " " ) ; } else { findSolution ( X , C , N ) ; } } var X = 21 ; var arr = [ 2 , 3 , 4 , 5 ] ; var N = arr . length ; countMinCoinsUtil ( X , arr , N ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function binCoff ( n , r ) { var val = 1 ; var i ; if ( r > ( n - r ) ) { r = ( n - r ) ; } for ( i = 0 ; i < r ; i ++ ) { val *= ( n - i ) ; val /= ( i + 1 ) ; } return val ; } function findWays ( n ) { n -- ; var a , b , ans ; a = binCoff ( 2 * n , n ) ; b = a / ( n + 1 ) ; ans = b ; return ans ; } var n = 4 ; document . write ( findWays ( n ) ) ;

Accumulator variables: i, n, val
Iterator variables: i
Javascript program:
var dp = Array . from ( Array ( 1010 ) , ( ) => Array ( 1010 ) ) ; function solve ( s , t ) { var n = s . length ; var r = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = 0 ; if ( i > 0 ) { dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j ] ) ; } if ( s [ i ] == t [ j ] ) { var ans = 1 ; if ( i > 0 && j > 0 ) { ans = 1 + dp [ i - 1 ] [ j - 1 ] ; } dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , ans ) ; r = Math . max ( r , dp [ i ] [ j ] ) ; } } } return ( n - r ) ; } var s = " " ; var t = " " ; document . write ( solve ( s , t ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function longestSubstring ( s , n ) { var index = new Map ( ) ; var answer = 0 ; var mask = 0 ; index [ mask ] = - 1 ; for ( var i = 0 ; i < n ; i ++ ) { var temp = s [ i ] . charCodeAt ( 0 ) - 97 ; mask ^= ( 1 << temp ) ; if ( index [ mask ] ) { answer = Math . max ( answer , i - index [ mask ] ) ; } else index [ mask ] = i ; for ( var j = 0 ; j < 26 ; j ++ ) { var mask2 = mask ^ ( 1 << j ) ; if ( index [ mask2 ] ) { answer = Math . max ( answer , i - index [ mask2 ] ) ; } } } return answer ; } var s = " " ; var n = s . length ; document . write ( longestSubstring ( s , n ) ) ;

Index/key variables: i, mask, mask2
Accumulator variables: i, j, mask
Iterator variables: i, j
Javascript program:
function countNums ( N ) { var dp = Array ( N ) ; for ( var i = 0 ; i < N ; i ++ ) dp [ i ] = Array ( 16 ) . fill ( 0 ) ; for ( i = 1 ; i <= 9 ; i ++ ) dp [ 0 ] [ i ] = 1 ; for ( i = 1 ; i < N ; i ++ ) { for ( j = 0 ; j < 10 ; j ++ ) { for ( k = 0 ; k < 16 ; k ++ ) { var xor = j ^ k ; dp [ i ] [ xor ] += dp [ i - 1 ] [ k ] ; } } } var count = 0 ; for ( i = 0 ; i < 10 ; i ++ ) count += dp [ N - 1 ] [ i ] ; document . write ( count ) ; } var N = 1 ; countNums ( N ) ;

Index/key variables: i, k, xor
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Javascript program:
function SubarrayWithMaxSum ( nums ) { let currMax = nums [ 0 ] , globalMax = nums [ 0 ] ; let endIndex = 0 ; let startIndex = 0 , globalMaxStartIndex = 0 ; for ( let i = 1 ; i < nums . length ; ++ i ) { if ( nums [ i ] > nums [ i ] + currMax ) { currMax = nums [ i ] ; } else if ( nums [ i ] < nums [ i ] + currMax ) { currMax = nums [ i ] + currMax ; } if ( currMax > globalMax ) { globalMax = currMax ; endIndex = i ; globalMaxStartIndex = startIndex ; } } for ( let i = globalMaxStartIndex ; i <= endIndex ; ++ i ) { document . write ( nums [ i ] + " " ) ; } } let arr = [ ] ; arr . push ( - 2 ) ; arr . push ( - 5 ) ; arr . push ( 6 ) ; arr . push ( - 2 ) ; arr . push ( - 3 ) ; arr . push ( 1 ) ; arr . push ( 5 ) ; arr . push ( - 6 ) ; SubarrayWithMaxSum ( arr ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function count ( a , M , N ) { let cnt = 0 ; for ( let i = 1 ; i <= M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { if ( i % a [ j ] == 0 ) { cnt ++ ; break ; } } } return cnt ; } let arr = [ 2 , 3 , 5 , 7 ] ; let m = 100 ; let n = arr . length ; document . write ( count ( arr , m , n ) ) ;

Index/key variables: j
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
var dp = Array . from ( Array ( 15 ) , ( ) => Array ( 10 ) . fill ( 0 ) ) ; function solve ( n , last , k ) { if ( n == 1 ) { if ( last == k ) { return ( k - 1 ) ; } else { return 1 ; } } if ( ( dp [ n ] [ last ] ) != 0 ) return dp [ n ] [ last ] ; if ( last == k ) { return dp [ n ] [ last ] = ( k - 1 ) * solve ( n - 1 , k , k ) + ( k - 1 ) * solve ( n - 1 , 1 , k ) ; } else { dp [ n ] [ last ] = solve ( n - 1 , k , k ) ; return dp [ n ] [ last ] ; } } var n = 2 , k = 3 ; var x = solve ( n , k , k ) + solve ( n , 1 , k ) ; document . write ( x ) ;

Index/key variables: last, n
Javascript program:
function maximumSum ( A , B , length , X , Y ) { var l = length ; var l1 = Math . min ( length , X ) ; var l2 = Math . min ( length , Y ) ; var dp = Array . from ( Array ( l1 + 1 ) , ( ) => Array ( l2 + 1 ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = 0 ; var max_sum = - 1000000000 ; for ( var i = 1 ; i <= l1 ; i ++ ) { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + A [ i - 1 ] ; max_sum = Math . max ( max_sum , dp [ i ] [ 0 ] ) ; } for ( var i = 1 ; i <= l2 ; i ++ ) { dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + B [ i - 1 ] ; max_sum = Math . max ( max_sum , dp [ 0 ] [ i ] ) ; } for ( var i = 1 ; i <= l1 ; i ++ ) { for ( var j = 1 ; j <= l2 ; j ++ ) { if ( i + j <= l ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] + A [ i + j - 1 ] , dp [ i ] [ j - 1 ] + B [ i + j - 1 ] ) ; max_sum = Math . max ( dp [ i ] [ j ] , max_sum ) ; } } return max_sum ; } var A = [ 1 , 2 , 3 , 4 , 5 ] ; var B = [ 5 , 4 , 3 , 2 , 1 ] ; var X = 3 , Y = 2 ; var N = A . length ; document . write ( maximumSum ( A , B , N , X , Y ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function reduceZero ( N ) { var dp = Array ( N + 1 ) . fill ( 1000000000 ) ; dp [ 0 ] = 0 ; for ( var i = 0 ; i <= N ; i ++ ) { for ( var j = 0 ; j < i . toString ( ) . length ; j ++ ) { dp [ i ] = Math . min ( dp [ i ] , dp [ i - ( i . toString ( ) [ j ] - ' ' ) ] + 1 ) ; } } return dp [ N ] ; } var N = 25 ; document . write ( reduceZero ( N ) ) ;

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printpenta ( n ) { if ( n < 0 ) return ; let first = 0 ; let second = 0 ; let third = 0 ; let fourth = 0 ; let fifth = 1 ; let curr = 0 ; if ( n == 0 n == 1 n == 2 n == 3 ) document . write ( first + " " ) ; else if ( n == 5 ) document . write ( fifth + " " ) ; else { for ( let i = 5 ; i < n ; i ++ ) { curr = first + second + third + fourth + fifth ; first = second ; second = third ; third = fourth ; fourth = fifth ; fifth = curr ; } document . write ( curr + " " ) ; } } let n = 10 ; printpenta ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let dp = new Array ( 100001 ) . fill ( - 1 ) . map ( ( t ) => new Array ( 20 ) . fill ( - 1 ) . map ( ( r ) => new Array ( 2 ) . fill ( - 1 ) ) ) ; function possibleBinaries ( pos , ones , sum , k ) { if ( ones == k ) return 0 ; if ( pos == 0 ) return ( sum == 0 ) ? 1 : 0 ; if ( dp [ pos ] [ ones ] [ sum ] != - 1 ) return dp [ pos ] [ ones ] [ sum ] ; let ret = possibleBinaries ( pos - 1 , ones + 1 , ( sum + 1 ) % 2 , k ) + possibleBinaries ( pos - 1 , 0 , sum , k ) ; dp [ pos ] [ ones ] [ sum ] = ret ; return dp [ pos ] [ ones ] [ sum ] ; } let N = 3 ; let K = 2 ; document . write ( possibleBinaries ( N , 0 , 0 , K ) ) ;

Index/key variables: ones, pos, sum
Javascript program:
var MOD = 1000000007 ; var dp = Array . from ( Array ( 101 ) , ( ) => Array ( 101 ) ) ; var N , M , K ; for ( var i = 0 ; i < 101 ; i ++ ) for ( var j = 0 ; j < 101 ; j ++ ) dp [ i ] [ j ] = new Array ( 101 ) . fill ( - 1 ) ; function CountWays ( i , j , k ) { if ( i >= N i < 0 j >= M j < 0 k < 0 ) return 0 ; if ( i == 0 && j == 0 && k == 0 ) return 1 ; if ( dp [ i ] [ j ] [ k ] != - 1 ) return dp [ i ] [ j ] [ k ] ; else dp [ i ] [ j ] [ k ] = ( CountWays ( i + 1 , j , k - 1 ) % MOD + CountWays ( i - 1 , j , k - 1 ) % MOD + CountWays ( i , j - 1 , k - 1 ) % MOD + CountWays ( i , j + 1 , k - 1 ) % MOD + CountWays ( i , j , k - 1 ) % MOD ) % MOD ; return dp [ i ] [ j ] [ k ] ; } N = 3 ; M = 3 ; K = 4 ; document . write ( CountWays ( 0 , 0 , K ) )

Index/key variables: i, j, k
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let prime = new Array ( 100001 ) ; function SieveOfEratosthenes ( ) { prime . fill ( true ) prime [ 0 ] = prime [ 1 ] = false ; for ( let p = 2 ; p * p <= 100000 ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= 100000 ; i += p ) prime [ i ] = false ; } } } function distinctPrimeSubSeq ( a , n , k ) { SieveOfEratosthenes ( ) ; let primes = new Array ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( prime [ a [ i ] ] ) primes . push ( a [ i ] ) ; } let l = primes . length ; primes . sort ( ( a , b ) => a - b ) let b = new Array ( ) ; let dp = new Array ( ) ; let sum = 0 ; for ( let i = 0 ; i < l ; ) { let count = 1 , x = a [ i ] ; i ++ ; while ( i < l && a [ i ] == x ) { count ++ ; i ++ ; } b . push ( count ) ; dp . push ( count ) ; sum += count ; } let of_length = 2 ; let len = dp . length ; let ans = 0 ; while ( of_length <= k ) { let freq = 0 ; let prev = 0 ; for ( let i = 0 ; i < ( len - 1 ) ; i ++ ) { freq += dp [ i ] ; let j = sum - freq ; let subseq = b [ i ] * j ; ans += subseq ; dp [ i ] = subseq ; prev += dp [ i ] ; } len -- ; sum = prev ; of_length ++ ; } ans += ( l + 1 ) ; return ans ; } let a = [ 1 , 2 , 2 , 3 , 3 , 4 , 5 ] ; let n = a . length ; let k = 3 ; document . write ( distinctPrimeSubSeq ( a , n , k ) ) ;

Index/key variables: i, p
Accumulator variables: ans, count, freq, i, len, of_length, p, prev, sum
Iterator variables: i, p