dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function find ( x , c ) { for ( let i = 0 ; i < x . length ; i ++ ) if ( x [ i ] == c ) return true ; return false ; } function addAllVowel ( str ) { let x = [ ' ' , ' ' , ' ' , ' ' , ' ' ] ; let y = [ ] ; let length = str . length ; if ( length < 5 ) document . write ( " " ) ; else { for ( let i = 0 ; i < length ; i ++ ) { if ( find ( x , str [ i ] ) && ! find ( y , str [ i ] ) ) y . push ( str [ i ] ) ; } let z = [ ] ; for ( let i = 0 ; i < 5 ; i ++ ) if ( ! find ( y , x [ i ] ) ) z . push ( x [ i ] ) ; if ( z . length == 0 ) document . write ( str + " " ) ; else { let cc = 0 ; let y1 = [ ] ; let ans = " " ; for ( let i = 0 ; i < length ; i ++ ) { if ( find ( x , str [ i ] ) && ! find ( y1 , str [ i ] ) ) { ans += str [ i ] ; y1 . push ( str [ i ] ) ; } else { ans += z [ cc ] ; cc ++ ; } if ( cc == z . length ) { for ( let j = i + 1 ; j < length ; j ++ ) ans += str [ j ] ; break ; } } document . write ( ans ) ; } } } let str = " " ; addAllVowel ( str ) ;

Index/key variables: cc, i, j
Accumulator variables: ans, cc, i, j
Iterator variables: i, j
Javascript program:
function minimumDays ( N , D1 , D2 ) { var ans = - 1000000000 ; var vect = [ ] ; for ( var i = 0 ; i < N ; i ++ ) vect . push ( [ D1 [ i ] , D2 [ i ] ] ) ; vect . sort ( ( a , b ) => a - b ) for ( var i = 0 ; i < N ; i ++ ) { if ( vect [ i ] [ 1 ] >= ans ) ans = vect [ i ] [ 1 ] ; else ans = vect [ i ] [ 0 ] ; } return ans ; } var N = 3 ; var D1 = [ 6 , 5 , 4 ] ; var D2 = [ 1 , 2 , 3 ] ; document . write ( minimumDays ( N , D1 , D2 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countSubstrings ( s ) { let ans = 0 ; let subs = 1 ; let pre = ' ' ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( pre == s [ i ] ) { subs += 1 ; } else { subs = 1 ; } ans += subs ; pre = s [ i ] ; } document . write ( ans ) ; } let s = " " ; countSubstrings ( s ) ;

Index/key variables: i
Accumulator variables: ans, i, subs
Iterator variables: i
Javascript program:
function solve ( v , n ) { let ans , ul , ll ; let first = 0 ; let second = 1 ; ll = v [ 0 ] [ first ] ; ul = v [ 0 ] [ second ] ; ans = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( ( v [ i ] [ first ] <= ul && v [ i ] [ first ] >= ll ) || ( v [ i ] [ second ] >= ll && v [ i ] [ second ] <= ul ) ) { if ( v [ i ] [ first ] > ll ) { ll = v [ i ] [ first ] ; } if ( v [ i ] [ second ] < ul ) { ul = v [ i ] [ second ] ; } } else if ( v [ i ] [ first ] > ul ) { ans += Math . abs ( ul - v [ i ] [ first ] ) ; ul = v [ i ] [ first ] ; ll = v [ i ] [ first ] ; } else if ( v [ i ] [ second ] < ll ) { ans += Math . abs ( ll - v [ i ] [ second ] ) ; ul = v [ i ] [ second ] ; ll = v [ i ] [ second ] ; } } return ans ; } let v = [ [ 1 , 3 ] , [ 2 , 5 ] , [ 6 , 8 ] , [ 1 , 2 ] , [ 2 , 3 ] ] ; let n = 5 ; document . write ( solve ( v , n ) ) ;

Index/key variables: first, i, second
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function preProcess ( n ) { let preProcessedCubes = [ ] ; for ( let i = 1 ; i * i * i <= n ; i ++ ) { let iThCube = i * i * i ; let cubeString = ( iThCube ) . toString ( ) ; preProcessedCubes . push ( cubeString ) ; } return preProcessedCubes ; } function findLargestCubeUtil ( num , preProcessedCubes ) { ( preProcessedCubes ) . reverse ( ) ; let totalCubes = preProcessedCubes . length ; for ( let i = 0 ; i < totalCubes ; i ++ ) { let currCube = preProcessedCubes [ i ] ; let digitsInCube = currCube . length ; let index = 0 ; let digitsInNumber = num . length ; for ( let j = 0 ; j < digitsInNumber ; j ++ ) { if ( num [ j ] == currCube [ index ] ) { index ++ ; } if ( digitsInCube == index ) { return currCube ; } } } return " " ; } function findLargestCube ( n ) { let preProcessedCubes = preProcess ( n ) ; let num = ( n ) . toString ( ) ; let ans = findLargestCubeUtil ( num , preProcessedCubes ) ; document . write ( " " + n + " " + ans + " " ) ; } let n ; n = 4125 ; findLargestCube ( n ) ; n = 876 ; findLargestCube ( n ) ;

Index/key variables: i, index, j
Accumulator variables: i, index, j
Iterator variables: i, j
Javascript program:
let n , p ; let rd = new Array ( 1100 ) ; let wt = new Array ( 1100 ) ; let cd = new Array ( 1100 ) ; let a = [ ] ; let b = [ ] ; let c = [ ] ; let ans ; function dfs ( w ) { if ( cd [ w ] == 0 ) return w ; if ( wt [ w ] < ans ) ans = wt [ w ] ; return dfs ( cd [ w ] ) ; } function solve ( arr ) { let i = 0 ; while ( i < p ) { let q = arr [ i ] [ 0 ] ; let h = arr [ i ] [ 1 ] ; let t = arr [ i ] [ 2 ] ; cd [ q ] = h ; wt [ q ] = t ; rd [ h ] = q ; i ++ ; } a = [ ] ; b = [ ] ; c = [ ] ; for ( let j = 1 ; j <= n ; ++ j ) if ( rd [ j ] == 0 && cd [ j ] > 0 ) { ans = 1000000000 ; let w = dfs ( j ) ; a . push ( j ) ; b . push ( w ) ; c . push ( ans ) ; } document . write ( a . length + " " ) ; for ( let j = 0 ; j < a . length ; ++ j ) document . write ( a [ j ] + " " + b [ j ] + " " + c [ j ] + " " ) ; } n = 9 ; p = 6 ; for ( let i = 0 ; i < 1100 ; i ++ ) rd [ i ] = cd [ i ] = wt [ i ] = 0 ; let arr = [ [ 7 , 4 , 98 ] , [ 5 , 9 , 72 ] , [ 4 , 6 , 10 ] , [ 2 , 8 , 22 ] , [ 9 , 7 , 17 ] , [ 3 , 1 , 66 ] ] ; solve ( arr ) ;

Index/key variables: h, i, j, q, w
Accumulator variables: i
Iterator variables: i, j
Javascript program:
function noAdjacentDup ( s1 ) { let n = s1 . length ; let s = s1 . split ( ' ' ) ; for ( let i = 1 ; i < n ; i ++ ) { if ( s [ i ] == s [ i - 1 ] ) { s [ i ] = ' ' ; while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ; i ++ ; } } return ( s ) ; } let s = " " ; document . write ( noAdjacentDup ( s ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function winner ( a , n , k ) { if ( k >= n - 1 ) return n ; let best = 0 , times = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] > best ) { best = a [ i ] ; if ( i ) times = 1 ; } else times += 1 ; if ( times >= k ) return best ; } return best ; } let a = [ 2 , 1 , 3 , 4 , 5 ] ; let n = a . length ; let k = 2 ; document . write ( winner ( a , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, times
Iterator variables: i
Javascript program:
function minimumSquare ( a , b ) { let result = 0 , rem = 0 ; if ( a < b ) { let temp = a ; a = b ; b = temp ; } while ( b > 0 ) { result += parseInt ( a / b ) ; let rem = a % b ; a = b ; b = rem ; } return result ; } let n = 13 , m = 29 ; document . write ( minimumSquare ( n , m ) ) ;

Accumulator variables: result
Javascript program:
const totalValidArrays = ( a , b , N ) => { let dp = new Array ( N + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( b [ N - 1 ] + 1 ) . fill ( 0 ) ) ; let pref = new Array ( N + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( b [ N - 1 ] + 1 ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = 1 ; for ( let i = 0 ; i <= b [ N - 1 ] ; i ++ ) { pref [ 0 ] [ i ] = 1 ; } for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = a [ i - 1 ] ; j <= b [ i - 1 ] ; j ++ ) { dp [ i ] [ j ] += pref [ i - 1 ] [ j ] ; pref [ i ] [ j ] += dp [ i ] [ j ] ; } for ( let j = 0 ; j <= b [ N - 1 ] ; j ++ ) { if ( j > 0 ) { pref [ i ] [ j ] += pref [ i ] [ j - 1 ] ; } } } let ans = 0 ; for ( let i = a [ N - 1 ] ; i <= b [ N - 1 ] ; i ++ ) { ans += dp [ N ] [ i ] ; } return ans ; } let A = [ 1 , 1 ] ; let B = [ 2 , 3 ] ; let N = A . length ; document . write ( totalValidArrays ( A , B , N ) ) ;

Index/key variables: N, i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
let INF = 1000000000 ; function minimumCost ( s ) { let N = s . length ; let A = [ ] , B = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( s [ i ] == " " ) { A . push ( i ) ; } else { B . push ( i ) ; } } let n1 = A . length ; let n2 = B . length ; let dp = new Array ( n1 + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( n2 + 1 ) . fill ( 0 ) ) ; for ( let i = 1 ; i <= n1 ; i ++ ) { dp [ i ] [ 0 ] = INF ; } for ( let i = 1 ; i <= n1 ; i ++ ) { for ( let j = 1 ; j <= n2 ; j ++ ) { dp [ i ] [ j ] = Math . min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j - 1 ] + Math . abs ( A [ i - 1 ] - B [ j - 1 ] ) ) ; } } return dp [ n1 ] [ n2 ] ; } let S = " " ; document . write ( minimumCost ( S ) ) ;

Index/key variables: i, j, n1, n2
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = 5000 ; function minDifference ( arr , n , q , m ) { for ( let i = 0 ; i < m ; i ++ ) { let L = q [ i ] [ 0 ] , R = q [ i ] [ 1 ] ; let ans = MAX ; for ( let i = L ; i < R ; i ++ ) { ans = Math . min ( ans , arr [ i ] ) ; } document . write ( ans + ' ' ) ; } } function minimumDifference ( arr , q , N , m ) { let diff = new Array ( N ) ; for ( let i = 0 ; i < N - 1 ; i ++ ) diff [ i ] = Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; minDifference ( diff , N - 1 , q , m ) ; } let arr = [ 2 , 6 , 1 , 8 , 3 , 4 ] ; let N = arr . length ; let Q = [ [ 0 , 3 ] , [ 1 , 5 ] , [ 4 , 5 ] ] ; let M = Q . length ; minimumDifference ( arr , Q , N , M ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let dp = new Array ( 100 ) . fill ( 0 ) . map ( ( ) => new Array ( 1 << 4 ) ) ; let primeIndex = new Map ( ) ; function countSetBits ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function countOfNumbers ( index , mask , N ) { if ( index == N + 1 ) { let countOfPrimes = countSetBits ( mask ) ; if ( countOfPrimes == 4 ) { return 1 ; } return 0 ; } let val = dp [ index ] [ mask ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( index == 1 ) { for ( let digit = N == 1 ? 0 : 1 ; digit <= 9 ; ++ digit ) { if ( primeIndex . has ( digit ) ) { let newMask = mask | ( 1 << primeIndex . get ( digit ) ) ; val += countOfNumbers ( index + 1 , newMask , N ) ; } else { val += countOfNumbers ( index + 1 , mask , N ) ; } } } else { for ( let digit = 0 ; digit <= 9 ; ++ digit ) { if ( primeIndex . has ( digit ) ) { let newMask = mask | ( 1 << primeIndex . get ( digit ) ) ; val += countOfNumbers ( index + 1 , newMask , N ) ; } else { val += countOfNumbers ( index + 1 , mask , N ) ; } } } return val ; } for ( let i = 0 ; i < 100 ; i ++ ) { for ( let j = 0 ; j < 1 << 4 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } primeIndex . set ( 2 , 0 ) ; primeIndex . set ( 3 , 1 ) ; primeIndex . set ( 5 , 2 ) ; primeIndex . set ( 7 , 3 ) ; let N = 4 ; document . write ( countOfNumbers ( 1 , 0 , N ) ) ;

Index/key variables: i, index, j, mask
Accumulator variables: count, i, j, val
Iterator variables: digit, i, j
Javascript program:
function countMinSteps ( A , B , N ) { let dp = new Array ( N + 1 ) . fill ( 0 ) ; for ( let i = 1 ; i <= N ; i ++ ) { if ( A [ i - 1 ] == B [ i - 1 ] ) { dp [ i ] = dp [ i - 1 ] ; } else { dp [ i ] = dp [ i - 1 ] + 1 ; } if ( i >= 2 && A [ i - 2 ] == B [ i - 1 ] && A [ i - 1 ] == B [ i - 2 ] ) { dp [ i ] = Math . min ( dp [ i ] , dp [ i - 2 ] + 1 ) ; } } return dp [ N ] ; } let A = " " ; let B = " " ; let N = A . length ; document . write ( countMinSteps ( A , B , N ) ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
let dp = new Array ( 50 ) . fill ( 0 ) . map ( ( ) => new Array ( 1 << 10 ) . fill ( 0 ) . map ( ( ) => new Array ( 2 ) . fill ( - 1 ) ) ) ; function countOfNumbers ( digit , mask , repeated , n ) { if ( digit == n + 1 ) { if ( repeated == true ) { return 1 ; } return 0 ; } if ( repeated == true ) { return Math . pow ( 10 , n - digit + 1 ) ; } let val = dp [ digit ] [ mask ] [ repeated ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( digit == 1 ) { for ( let i = ( n == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { if ( mask & ( 1 << i ) ) { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , 1 , n ) ; } else { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , 0 , n ) ; } } } else { for ( let i = 0 ; i <= 9 ; ++ i ) { if ( mask & ( 1 << i ) ) { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , 1 , n ) ; } else { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , 0 , n ) ; } } } return val ; } function countNDigitNumber ( N ) { document . write ( countOfNumbers ( 1 , 0 , 0 , N ) ) ; } let N = 2 ; countNDigitNumber ( N ) ;

Index/key variables: digit, mask, repeated
Accumulator variables: val
Iterator variables: i
Javascript program:
function getMaximum ( S , T ) { if ( S . indexOf ( " " ) > - 1 ) return T ; if ( T . indexOf ( " " ) > - 1 ) return S ; return S . length > T . length ? S : T ; } function recursion ( arr , idx , N , K , dp ) { if ( K == 0 ) { return " " ; } if ( K < 0 idx == N ) { return " " ; } if ( dp [ idx ] [ K ] != " " ) return dp [ idx ] [ K ] ; let include = String ( idx + 1 ) + recursion ( arr , 0 , N , K - arr [ idx ] , dp ) ; let exclude = recursion ( arr , idx + 1 , N , K , dp ) ; return ( dp [ idx ] [ K ] = getMaximum ( include , exclude ) ) ; } function largestNumber ( arr , N , K ) { let dp = new Array ( N + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( K + 1 ) . fill ( - 1 ) ) ; let ans = recursion ( arr , 0 , N , K , dp ) ; return ans == " " ? " " : ans ; } let arr = [ 3 , 12 , 9 , 5 , 3 , 4 , 6 , 5 , 10 ] ; let K = 14 ; let N = arr . length ; document . write ( largestNumber ( arr , N , K ) ) ;

Index/key variables: K, idx
Javascript program:
function countOfNumbers ( digit , prev , n ) { if ( digit == n + 1 ) { return 1 ; } let val = dp [ digit ] [ prev ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( digit == 1 ) { for ( let i = ( n == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , n ) ; } } else { for ( let i = 0 ; i <= 9 ; ++ i ) { if ( ( i & prev ) == 0 ) { val += countOfNumbers ( digit + 1 , i , n ) ; } } } return val ; } let dp = Array ( 100 ) . fill ( ) . map ( ( ) => Array ( 10 ) . fill ( - 1 ) ) ; let N = 3 ; document . write ( countOfNumbers ( 1 , 0 , N ) + " " ) ;

Index/key variables: digit, prev
Accumulator variables: val
Iterator variables: i
Javascript program:
function preProcess ( mat , dp , n , m ) { for ( let i = 0 ; i < m ; i ++ ) { dp [ 0 ] [ i ] = mat [ 0 ] [ i ] ; } for ( let i = 1 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + mat [ i ] [ j ] ; } } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 1 ; j < m ; j ++ ) { dp [ i ] [ j ] += dp [ i ] [ j - 1 ] ; } } } function sumQuery ( dp , tli , tlj , rbi , rbj ) { let res = dp [ rbi ] [ rbj ] ; if ( tli > 0 ) res = res - dp [ tli - 1 ] [ rbj ] ; if ( tlj > 0 ) res = res - dp [ rbi ] [ tlj - 1 ] ; if ( tli > 0 && tlj > 0 ) res = res + dp [ tli - 1 ] [ tlj - 1 ] ; return res ; } function maxSubMatrixSumQueries ( mat , n , m , queries , q ) { let dp = Array ( n ) . fill ( ) . map ( ( ) => Array ( m ) ) ; preProcess ( mat , dp , n , m ) ; let maxSum = new Array ( queries . length ) . fill ( 0 ) ; for ( let qi = 0 ; qi < q ; qi ++ ) { for ( let i = 0 ; i < n - queries [ qi ] [ 0 ] + 1 ; i ++ ) { for ( let j = 0 ; j < m - queries [ qi ] [ 1 ] + 1 ; j ++ ) { maxSum [ qi ] = Math . max ( maxSum [ qi ] , sumQuery ( dp , i , j , i + queries [ qi ] [ 0 ] - 1 , j + queries [ qi ] [ 1 ] - 1 ) ) ; } } } return maxSum ; } let n = 3 , m = 4 ; let mat = [ [ 1 , 2 , 3 , 9 ] , [ 4 , 5 , 6 , 2 ] , [ 8 , 3 , 2 , 6 ] ] ; let Q = 3 ; let Queries = [ [ 1 , 1 ] , [ 2 , 2 ] , [ 3 , 3 ] ] ; let maxSum = maxSubMatrixSumQueries ( mat , n , m , Queries , Q ) ; for ( let i = 0 ; i < Q ; i ++ ) { document . write ( maxSum [ i ] + " " ) ; }

Index/key variables: i, j, qi, rbi, rbj
Accumulator variables: i, j, qi
Iterator variables: i, j, qi
Javascript program:
let dp = new Array ( 1005 ) . fill ( 0 ) . map ( ( ) => new Array ( 1005 ) . fill ( - 1 ) ) ; function KvisibleFromLeft ( N , K ) { if ( dp [ N ] [ K ] != - 1 ) return dp [ N ] [ K ] ; if ( N == K ) return dp [ N ] [ K ] = 1 ; if ( K == 1 ) { let ans = 1 ; for ( let i = 1 ; i < N ; i ++ ) ans *= i ; return dp [ N ] [ K ] = ans ; } return dp [ N ] [ K ] = KvisibleFromLeft ( N - 1 , K - 1 ) + ( N - 1 ) * KvisibleFromLeft ( N - 1 , K ) ; } let N = 5 , K = 2 ; document . write ( KvisibleFromLeft ( N , K ) + " " )

Index/key variables: K, N
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function power ( x , y , p ) { let res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } function kvowelwords ( N , K ) { let i , j ; let MOD = 1000000007 ; let dp = new Array ( N + 1 ) for ( i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( K + 1 ) ; } let sum = 1 ; for ( i = 1 ; i <= N ; i ++ ) { dp [ i ] [ 0 ] = sum * 21 ; dp [ i ] [ 0 ] %= MOD ; sum = dp [ i ] [ 0 ] ; for ( j = 1 ; j <= K ; j ++ ) { if ( j > i ) dp [ i ] [ j ] = 0 ; else if ( j == i ) { dp [ i ] [ j ] = power ( 5 , i , MOD ) ; } else { dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] * 5 ; } dp [ i ] [ j ] %= MOD ; sum += dp [ i ] [ j ] ; sum %= MOD ; } } return sum ; } let N = 3 ; let K = 3 ; document . write ( kvowelwords ( N , K ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function maxBoundary ( N , V ) { let dp = new Array ( N ) . fill ( 0 ) . map ( ( ) => new Array ( 2 ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = V [ 0 ] [ 0 ] ; dp [ 0 ] [ 1 ] = V [ 0 ] [ 1 ] ; for ( let i = 1 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = V [ i ] [ 0 ] ; let height1 = Math . abs ( V [ i - 1 ] [ 1 ] - V [ i ] [ 1 ] ) ; let height2 = Math . abs ( V [ i - 1 ] [ 0 ] - V [ i ] [ 1 ] ) ; dp [ i ] [ 0 ] += Math . max ( height1 + dp [ i - 1 ] [ 0 ] , height2 + dp [ i - 1 ] [ 1 ] ) ; dp [ i ] [ 1 ] = V [ i ] [ 1 ] ; let vertical1 = Math . abs ( V [ i ] [ 0 ] - V [ i - 1 ] [ 1 ] ) ; let vertical2 = Math . abs ( V [ i ] [ 0 ] - V [ i - 1 ] [ 0 ] ) ; dp [ i ] [ 1 ] += Math . max ( vertical1 + dp [ i - 1 ] [ 0 ] , vertical2 + dp [ i - 1 ] [ 1 ] ) ; } document . write ( Math . max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ) ; } let N = 5 ; let V = [ [ 2 , 5 ] , [ 3 , 8 ] , [ 1 , 10 ] , [ 7 , 14 ] , [ 2 , 5 ] , ] ; maxBoundary ( N , V ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function NumberOfways ( N , K ) { let dp = Array . from ( { length : N + 1 } , ( _ , i ) => 0 ) ; dp [ 0 ] = 1 ; for ( let row = 1 ; row < K + 1 ; row ++ ) { for ( let col = 1 ; col < N + 1 ; col ++ ) { if ( col >= row ) dp [ col ] = dp [ col ] + dp [ col - row ] ; } } return ( dp [ N ] ) ; } let N = 8 ; let K = 2 ; document . write ( NumberOfways ( N , K ) ) ;

Index/key variables: N, col
Accumulator variables: col, row
Iterator variables: col, row
Javascript program:
function findAPSequence ( arr , N , Q , M ) { var dp = Array ( N + 5 ) . fill ( 0 ) ; for ( i = 0 ; i + 1 < N ; ) { var j = i + 1 ; while ( j + 1 < N && arr [ j + 1 ] - arr [ j ] == arr [ i + 1 ] - arr [ i ] ) j ++ ; for ( k = i ; k < j ; k ++ ) { dp [ k ] = j - k ; } i = j ; } for ( i = 0 ; i < M ; i ++ ) { if ( dp [ Q [ i ] [ 0 ] ] >= Q [ i ] [ 1 ] - Q [ i ] [ 0 ] ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } } var arr = [ 1 , 3 , 5 , 7 , 6 , 5 , 4 , 1 ] ; var Q = [ [ 0 , 3 ] , [ 3 , 4 ] , [ 2 , 4 ] ] ; var N = arr . length ; var M = Q . length ; findAPSequence ( arr , N , Q , M ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, k
Javascript program:
let dp = new Array ( 100 ) ; for ( let i = 0 ; i < 100 ; i ++ ) { dp [ i ] = new Array ( 100 ) ; for ( let j = 0 ; j < 100 ; j ++ ) { dp [ i ] [ j ] = new Array ( 100 ) ; for ( let k = 0 ; k < 100 ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; } } function minSumDifference ( arr , n , k1 , k2 , sum1 , sum2 ) { if ( n < 0 ) { if ( k1 == 0 && k2 == 0 ) { return Math . abs ( sum1 - sum2 ) ; } else { return Number . MAX_VALUE ; } } if ( dp [ n ] [ sum1 ] [ sum2 ] != - 1 ) { return dp [ n ] [ sum1 ] [ sum2 ] ; } let op1 = Number . MAX_VALUE ; let op2 = Number . MAX_VALUE ; let op3 = Number . MAX_VALUE ; if ( k1 > 0 ) { op1 = minSumDifference ( arr , n - 1 , k1 - 1 , k2 , sum1 + arr [ n ] , sum2 ) ; } if ( k2 > 0 ) { op2 = minSumDifference ( arr , n - 1 , k1 , k2 - 1 , sum1 , sum2 + arr [ n ] ) ; } op3 = minSumDifference ( arr , n - 1 , k1 , k2 , sum1 , sum2 ) ; dp [ n ] [ sum1 ] [ sum2 ] = Math . min ( op1 , Math . min ( op2 , op3 ) ) ; return dp [ n ] [ sum1 ] [ sum2 ] ; } let arr = [ 12 , 3 , 5 , 6 , 7 , 17 ] ; let K = 2 ; let N = arr . length ; document . write ( minSumDifference ( arr , N - 1 , K , K , 0 , 0 ) ) ;

Index/key variables: i, j, k, n, sum1, sum2
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function find ( A , B , C , N ) { let arr = new Array ( N ) . fill ( 0 ) ; arr [ 0 ] = A ; arr [ 1 ] = B ; arr [ 2 ] = C ; for ( let i = 3 ; i < N ; i ++ ) { arr [ i ] = arr [ i - 1 ] + arr [ i - 2 ] + arr [ i - 3 ] ; } return arr [ N - 1 ] ; } let A = 1 , B = 3 , C = 2 , N = 4 ; document . write ( find ( A , B , C , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function daysToCure ( arr , N , P ) { var risk = 0 ; var normal_risk = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= 60 arr [ i ] <= 10 ) { risk ++ ; } else { normal_risk ++ ; } } var days = parseInt ( ( risk / P ) + ( normal_risk / P ) ) ; if ( risk % P > 0 ) { days ++ ; } if ( normal_risk % P > 0 ) { days ++ ; } document . write ( days ) ; } var arr = [ 9 , 80 , 27 , 72 , 79 ] ; var N = arr . length ; var P = 2 ; daysToCure ( arr , N , P ) ;

Index/key variables: i
Accumulator variables: days, i, normal_risk, risk
Iterator variables: i
Javascript program:
let M = 100 ; function cntNum ( X , i , prod , K , st , tight , dp ) { if ( i >= X . length prod > K ) { return prod == K ? 1 : 0 ; } if ( dp [ prod ] [ i ] [ tight ] [ st ] != - 1 ) { return dp [ prod ] [ i ] [ tight ] [ st ] ; } let res = 0 ; let end = tight > 0 ? X [ i ] - ' ' : 9 ; for ( let j = 0 ; j <= end ; j ++ ) { if ( j == 0 && st == 0 ) { res += cntNum ( X , i + 1 , prod , K , 0 , ( tight & ( ( j == end ) ? 1 : 0 ) ) , dp ) ; } else { res += cntNum ( X , i + 1 , prod * j , K , 1 , ( tight & ( ( j == end ) ? 1 : 0 ) ) , dp ) ; } } return dp [ prod ] [ i ] [ tight ] [ st ] = res ; } function UtilCntNumRange ( L , R , K ) { let str = ( R ) . toString ( ) ; 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 ] = new Array ( 2 ) ; for ( let l = 0 ; l < 2 ; l ++ ) dp [ i ] [ j ] [ k ] [ l ] = - 1 ; } } } let cntR = cntNum ( str , 0 , 1 , K , 0 , 1 , dp ) ; str = ( L - 1 ) . toString ( ) ; for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { for ( let k = 0 ; k < 2 ; k ++ ) for ( let l = 0 ; l < 2 ; l ++ ) dp [ i ] [ j ] [ k ] [ l ] = - 1 ; } } let cntL = cntNum ( str , 0 , 1 , K , 0 , 1 , dp ) ; return ( cntR - cntL ) ; } let L = 20 , R = 10000 , K = 14 ; document . write ( UtilCntNumRange ( L , R , K ) ) ;

Index/key variables: i, j, k, l, prod, st, tight
Accumulator variables: i, j, k, l, res
Iterator variables: i, j, k, l
Javascript program:
function countVowelPermutation ( n ) { let MOD = ( 1e9 + 7 ) ; let dp = new Array ( n + 1 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < 5 ; i ++ ) { dp [ 1 ] [ i ] = 1 ; } let relation = [ [ 1 ] , [ 0 , 2 ] , [ 0 , 1 , 3 , 4 ] , [ 2 , 4 ] , [ 0 ] ] ; for ( let i = 1 ; i < n ; i ++ ) { for ( let u = 0 ; u < 5 ; u ++ ) { dp [ i + 1 ] [ u ] = 0 ; for ( let v in relation [ u ] ) { dp [ i + 1 ] [ u ] += dp [ i ] [ v ] % MOD ; } } } let ans = 0 ; for ( let i = 0 ; i < 5 ; i ++ ) { ans = ( ans + dp [ n ] [ i ] ) % MOD ; } return ans ; } let N = 2 ; document . write ( countVowelPermutation ( N ) ) ;

Index/key variables: i, n, u, v
Accumulator variables: i, u
Iterator variables: i, u, v