dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
const MAX = 100 ; function isPossible ( n , index , modulo , M , arr , dp ) { modulo = ( ( modulo % M ) + M ) % M ; if ( index == n ) { if ( modulo == 0 ) { return 1 ; } return 0 ; } if ( dp [ index ] [ modulo ] != - 1 ) { return dp [ index ] [ modulo ] ; } var placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ; var placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ; var res = placeAdd ; dp [ index ] [ modulo ] = res ; return res ; } var arr = [ 1 , 2 , 3 , 4 , 6 ] ; var n = arr . length ; var M = 4 ; var dp = Array ( n + 1 ) ; for ( i = 0 ; i < n + 1 ; i ++ ) { dp [ i ] = Array ( MAX ) . fill ( - 1 ) ; } var res ; if ( isPossible ( n , 1 , arr [ 0 ] , M , arr , dp ) == 1 ) { res = true ; } else { res = false ; } document . write ( res ? " " : " " ) ;

Index/key variables: i, index, modulo
Accumulator variables: i
Iterator variables: i
Boolean variables: res
Javascript program:
function findCommon ( ar1 , ar2 , ar3 , n1 , n2 , n3 ) { var i = 0 , j = 0 , k = 0 ; while ( i < n1 && j < n2 && k < n3 ) { if ( ar1 [ i ] == ar2 [ j ] && ar2 [ j ] == ar3 [ k ] ) { document . write ( ar1 [ i ] + " " ) ; i ++ ; j ++ ; k ++ ; } else if ( ar1 [ i ] < ar2 [ j ] ) i ++ ; else if ( ar2 [ j ] < ar3 [ k ] ) j ++ ; else k ++ ; } } var ar1 = [ 1 , 5 , 10 , 20 , 40 , 80 ] ; var ar2 = [ 6 , 7 , 20 , 80 , 100 ] ; var ar3 = [ 3 , 4 , 15 , 20 , 30 , 70 , 80 , 120 ] ; var n1 = ar1 . length ; var n2 = ar2 . length ; var n3 = ar3 . length ; document . write ( " " ) ; findCommon ( ar1 , ar2 , ar3 , n1 , n2 , n3 ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Javascript program:
var dp = Array ( 100 ) . fill ( 0 ) ; function dfs ( a , v , u , parent ) { dp [ u ] = a [ u - 1 ] ; var maximum = 0 ; for ( var child of v [ u ] ) { if ( child == parent ) continue ; dfs ( a , v , child , u ) ; maximum = Math . max ( maximum , dp [ child ] ) ; } dp [ u ] += maximum ; } function maximumValue ( a , v ) { dfs ( a , v , 1 , 0 ) ; return dp [ 1 ] ; } var n = 14 ; var v = Array . from ( Array ( n + 1 ) , ( ) => Array ( ) ) ; for ( var i = 0 ; i < v . length ; i ++ ) v [ i ] = [ ] ; v [ 1 ] . push ( 2 ) ; v [ 2 ] . push ( 1 ) ; v [ 1 ] . push ( 3 ) ; v [ 3 ] . push ( 1 ) ; v [ 1 ] . push ( 4 ) ; v [ 4 ] . push ( 1 ) ; v [ 2 ] . push ( 5 ) ; v [ 5 ] . push ( 2 ) ; v [ 2 ] . push ( 6 ) ; v [ 6 ] . push ( 2 ) ; v [ 3 ] . push ( 7 ) ; v [ 7 ] . push ( 3 ) ; v [ 4 ] . push ( 8 ) ; v [ 8 ] . push ( 4 ) ; v [ 4 ] . push ( 9 ) ; v [ 9 ] . push ( 4 ) ; v [ 4 ] . push ( 10 ) ; v [ 10 ] . push ( 4 ) ; v [ 5 ] . push ( 11 ) ; v [ 11 ] . push ( 5 ) ; v [ 5 ] . push ( 12 ) ; v [ 12 ] . push ( 5 ) ; v [ 7 ] . push ( 13 ) ; v [ 13 ] . push ( 7 ) ; v [ 7 ] . push ( 14 ) ; v [ 14 ] . push ( 7 ) ; var a = [ 3 , 2 , 1 , 10 , 1 , 3 , 9 , 1 , 5 , 3 , 4 , 5 , 9 , 8 ] ; document . write ( maximumValue ( a , v ) ) ;

Index/key variables: child, i, u
Accumulator variables: i
Iterator variables: child, i
Javascript program:
function findCommon ( ar1 , ar2 , ar3 , n1 , n2 , n3 ) { var i = 0 , j = 0 , k = 0 ; var prev1 , prev2 , prev3 ; prev1 = prev2 = prev3 = - 1000000000 ; while ( i < n1 && j < n2 && k < n3 ) { while ( ar1 [ i ] == prev1 && i < n1 ) i ++ ; while ( ar2 [ j ] == prev2 && j < n2 ) j ++ ; while ( ar3 [ k ] == prev3 && k < n3 ) k ++ ; if ( ar1 [ i ] == ar2 [ j ] && ar2 [ j ] == ar3 [ k ] ) { document . write ( ar1 [ i ] + " " ) ; prev1 = ar1 [ i ] ; prev2 = ar2 [ j ] ; prev3 = ar3 [ k ] ; i ++ ; j ++ ; k ++ ; } else if ( ar1 [ i ] < ar2 [ j ] ) { prev1 = ar1 [ i ] ; i ++ ; } else if ( ar2 [ j ] < ar3 [ k ] ) { prev2 = ar2 [ j ] ; j ++ ; } else { prev3 = ar3 [ k ] ; k ++ ; } } } var ar1 = [ 1 , 5 , 10 , 20 , 40 , 80 , 80 ] ; var ar2 = [ 6 , 7 , 20 , 80 , 80 , 100 ] ; var ar3 = [ 3 , 4 , 15 , 20 , 30 , 70 , 80 , 80 , 120 ] ; var n1 = ar1 . length ; var n2 = ar2 . length ; var n3 = ar3 . length ; document . write ( " " ) ; findCommon ( ar1 , ar2 , ar3 , n1 , n2 , n3 ) ;

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

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function binarySearch ( arr , l , r , x ) { if ( r >= l ) { let mid = l + Math . floor ( ( r - l ) / 2 ) ; if ( arr [ mid ] == x ) return mid ; if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ; return binarySearch ( arr , mid + 1 , r , x ) ; } return - 1 ; } function findPos ( arr , key ) { let l = 0 , h = 1 ; let val = arr [ 0 ] ; while ( val < key ) { l = h ; h = 2 * h ; val = arr [ h ] ; } return binarySearch ( arr , l , h , key ) ; } let arr = [ 3 , 5 , 7 , 9 , 10 , 90 , 100 , 130 , 140 , 160 , 170 ] ; let ans = findPos ( arr , 10 ) ; if ( ans == - 1 ) document . write ( " " ) ; else document . write ( " " + ans ) ;

Index/key variables: h, mid
Javascript program:
let depth = 14 ; let ways = new Array ( 16 ) ; for ( let i = 0 ; i < 16 ; i ++ ) { ways [ i ] = new Array ( 16 ) ; for ( let j = 0 ; j < 16 ; j ++ ) { ways [ i ] [ j ] = new Array ( 16 ) ; for ( let k = 0 ; k < 16 ; k ++ ) { ways [ i ] [ j ] [ k ] = 0 ; } } } let stepNum ; function preprocess ( list ) { ways [ 0 ] [ 8 ] [ 8 ] = 1 ; for ( let N = 1 ; N <= 14 ; N ++ ) { for ( let i = 1 ; i < depth ; i ++ ) { for ( let j = 1 ; j < depth ; j ++ ) { ways [ N ] [ i ] [ j ] = ways [ N - 1 ] [ i ] [ j + 1 ] + ways [ N - 1 ] [ i ] [ j - 1 ] + ways [ N - 1 ] [ i + 1 ] [ j ] + ways [ N - 1 ] [ i - 1 ] [ j ] + ways [ N - 1 ] [ i + 1 ] [ j - 1 ] + ways [ N - 1 ] [ i - 1 ] [ j + 1 ] ; } } list [ N ] = ways [ N ] [ 8 ] [ 8 ] ; } } let list = new Array ( 15 ) ; list . fill ( 0 ) ; preprocess ( list ) ; let steps = 4 ; document . write ( " " + " " + list [ steps ] ) ;

Index/key variables: N, i, j, k, steps
Accumulator variables: N, i, j, k
Iterator variables: N, i, j, k
Javascript program:
function answer ( n ) { let dp = new Array ( n + 1 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } if ( n == 1 ) return 10 ; for ( let j = 0 ; j <= 9 ; j ++ ) dp [ 1 ] [ j ] = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { for ( let j = 0 ; j <= 9 ; j ++ ) { if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ; else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ; } } let sum = 0 ; for ( let j = 1 ; j <= 9 ; j ++ ) sum += dp [ n ] [ j ] ; return sum ; } let n = 2 ; document . write ( answer ( n ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function lcs ( a , b ) { let m = a . length ; let n = b . length ; let X = a . split ( ' ' ) ; let Y = b . split ( ' ' ) ; let L = new Array ( m + 1 ) ; for ( let i = 0 ; i <= m ; i ++ ) { L [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j <= n ; j ++ ) { L [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i <= m ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) { L [ i ] [ j ] = 0 ; } else if ( X [ i - 1 ] == Y [ j - 1 ] ) { L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; } else { L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } } let index = L [ m ] [ n ] ; let lcs = new Array ( index + 1 ) ; lcs . fill ( ' ' ) ; let i = m , j = n ; while ( i > 0 && j > 0 ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { lcs [ index - 1 ] = X [ i - 1 ] ; i -- ; j -- ; index -- ; } else if ( L [ i - 1 ] [ j ] > L [ i ] [ j - 1 ] ) { i -- ; } else { j -- ; } } let ans = " " ; for ( let x = 0 ; x < lcs . length ; x ++ ) { ans += lcs [ x ] ; } return ans ; } function longestPalSubseq ( str ) { let rev = str ; rev = reverse ( rev ) ; return lcs ( str , rev ) ; } function reverse ( str ) { let ans = " " ; let try1 = str . split ( ' ' ) ; for ( let i = try1 . length - 1 ; i >= 0 ; i -- ) { ans += try1 [ i ] ; } return ans ; } let str = " " ; document . write ( longestPalSubseq ( str ) ) ;

Index/key variables: i, j, m, n, x
Accumulator variables: ans, i, index, j, x
Iterator variables: i, j, x
Javascript program:
function productSubSeqCount ( arr , k ) { let n = arr . length ; let dp = new Array ( k + 1 ) ; for ( let i = 0 ; i < k + 1 ; i ++ ) { dp [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < n + 1 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= k ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ; if ( arr [ j - 1 ] <= i && arr [ j - 1 ] > 0 ) dp [ i ] [ j ] += dp [ parseInt ( i / arr [ j - 1 ] , 10 ) ] [ j - 1 ] + 1 ; } } return dp [ k ] [ n ] ; } let A = [ 1 , 2 , 3 , 4 ] ; let k = 10 ; document . write ( productSubSeqCount ( A , k ) ) ;

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findSingle ( ar , ar_size ) { let res = ar [ 0 ] ; for ( let i = 1 ; i < ar_size ; i ++ ) res = res ^ ar [ i ] ; return res ; } let ar = [ 2 , 3 , 5 , 4 , 5 , 3 , 4 ] ; let n = ar . length ; document . write ( " " + findSingle ( ar , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function singleNumber ( nums , n ) { let m = new Map ( ) ; let sum1 = 0 , sum2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! m . has ( nums [ i ] ) ) { sum1 += nums [ i ] ; m . set ( nums [ i ] , 1 ) ; } sum2 += nums [ i ] ; } return ( 2 * ( sum1 ) - sum2 ) ; } let a = [ 2 , 3 , 5 , 4 , 5 , 3 , 4 ] ; let n = 7 ; document . write ( singleNumber ( a , n ) + " " ) ; let b = [ 15 , 18 , 16 , 18 , 16 , 15 , 89 ] ; document . write ( singleNumber ( b , n ) ) ;

Index/key variables: i
Accumulator variables: i, sum1, sum2
Iterator variables: i
Javascript program:
function isPresent ( B , m , x ) { for ( let i = 0 ; i < m ; i ++ ) if ( B [ i ] == x ) return true ; return false ; } function findMaxSubarraySumUtil ( A , B , n , m ) { let max_so_far = - 2147483648 , curr_max = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( isPresent ( B , m , A [ i ] ) ) { curr_max = 0 ; continue ; } curr_max = Math . max ( A [ i ] , curr_max + A [ i ] ) ; max_so_far = Math . max ( max_so_far , curr_max ) ; } return max_so_far ; } function findMaxSubarraySum ( A , B , n , m ) { let maxSubarraySum = findMaxSubarraySumUtil ( A , B , n , m ) ; if ( maxSubarraySum == - 2147483648 ) { document . write ( " " + " " + " " ) ; } else { document . write ( " " + maxSubarraySum ) ; } } let A = [ 3 , 4 , 5 , - 4 , 6 ] ; let B = [ 1 , 8 , 5 ] ; let n = A . length ; let m = B . length ; findMaxSubarraySum ( A , B , n , m ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function nonDecNums ( n ) { let a = new Array ( n + 1 ) for ( let i = 0 ; i < n + 1 ; i ++ ) { a [ i ] = new Array ( 10 ) ; } for ( let i = 0 ; i <= 9 ; i ++ ) a [ 0 ] [ i ] = 1 ; for ( let i = 1 ; i <= n ; i ++ ) a [ i ] [ 9 ] = 1 ; for ( let i = 1 ; i <= n ; i ++ ) for ( let j = 8 ; j >= 0 ; j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ; return a [ n ] [ 0 ] ; } let n = 2 ; document . write ( " " + nonDecNums ( n ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MOD = 1000000007 ; function countBT ( h ) { let dp = new Array ( h + 1 ) ; dp . fill ( 0 ) ; dp [ 0 ] = 1 ; dp [ 1 ] = 1 ; for ( let i = 2 ; i <= h ; ++ i ) dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD ; return dp [ h ] ; } let h = 3 ; document . write ( " " + countBT ( h ) ) ;

Index/key variables: h, i
Iterator variables: i
Javascript program:
let MAX_CHAR = 256 ; function printDistinct ( str ) { let n = str . length ; let count = new Array ( MAX_CHAR ) ; let index = new Array ( MAX_CHAR ) ; for ( let i = 0 ; i < MAX_CHAR ; i ++ ) { count [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { let x = str [ i ] . charCodeAt ( 0 ) ; ++ count [ x ] ; if ( count [ x ] == 1 && x != ' ' ) index [ x ] = i ; if ( count [ x ] == 2 ) index [ x ] = n ; } index . sort ( function ( a , b ) { return a - b } ) ; for ( let i = 0 ; i < MAX_CHAR && index [ i ] != n ; i ++ ) document . write ( str [ index [ i ] ] ) ; } let str = " " ; printDistinct ( str ) ;

Index/key variables: i, x
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX_LEN = 110 ; let DP = new Array ( MAX_LEN ) ; for ( let i = 0 ; i < DP . length ; i ++ ) { DP [ i ] = new Array ( MAX_LEN ) ; for ( let j = 0 ; j < DP [ i ] . length ; j ++ ) { DP [ i ] [ j ] = new Array ( MAX_LEN ) ; for ( let k = 0 ; k < MAX_LEN ; k ++ ) { DP [ i ] [ j ] [ k ] = 0 ; } } } function length ( a , b , c ) { if ( a < 0 b < 0 c < 0 ) if ( DP [ a ] [ b ] != - 1 ) return DP [ a ] [ b ] ; if ( a == 0 && b == 0 ) return ( DP [ a ] [ b ] = c ) ; if ( a == 0 && c == 0 ) return ( DP [ a ] [ b ] = b ) ; if ( b == 0 && c == 0 ) return ( DP [ a ] [ b ] = a ) ; if ( a == 0 ) return ( DP [ a ] [ b ] = length ( a + 1 , b - 1 , c - 1 ) ) ; if ( b == 0 ) return ( DP [ a ] [ b ] = length ( a - 1 , b + 1 , c - 1 ) ) ; if ( c == 0 ) return ( DP [ a ] [ b ] = length ( a - 1 , b - 1 , c + 1 ) ) ; DP [ a ] [ b ] = Math . min ( length ( a - 1 , b - 1 , c + 1 ) , Math . min ( length ( a - 1 , b + 1 , c - 1 ) , length ( a + 1 , b - 1 , c - 1 ) ) ) ; return DP [ a ] [ b ] ; } function stringReduction ( str ) { let n = str . length ; let count = new Array ( 3 ) ; for ( let i = 0 ; i < 3 ; i ++ ) { count [ i ] = 0 ; } for ( let i = 0 ; i < n ; ++ i ) count [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = 0 ; i <= count [ 0 ] ; ++ i ) for ( let j = 0 ; j < count [ 1 ] ; ++ j ) for ( let k = 0 ; k < count [ 2 ] ; ++ k ) DP [ i ] [ j ] [ k ] = - 1 ; return length ( count [ 0 ] , count [ 1 ] , count [ 2 ] ) ; } let str = " " ; document . write ( stringReduction ( str ) ) ;

Index/key variables: a, b, i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function equilibrium ( arr , n ) { var i , j ; var leftsum , rightsum ; for ( i = 0 ; i < n ; ++ i ) { leftsum = 0 ; rightsum = 0 ; for ( let j = 0 ; j < i ; j ++ ) leftsum += arr [ j ] ; for ( let j = i + 1 ; j < n ; j ++ ) rightsum += arr [ j ] ; if ( leftsum == rightsum ) return i ; } return - 1 ; } var arr = new Array ( - 7 , 1 , 5 , 2 , - 4 , 3 , 0 ) ; n = arr . length ; document . write ( equilibrium ( arr , n ) ) ;

Index/key variables: j
Accumulator variables: j, leftsum, rightsum
Iterator variables: i, j
Javascript program:
let MAX = 100 ; function countEndless ( input , n ) { let row = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { row [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { row [ i ] [ j ] = false ; } } let col = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { col [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { col [ i ] [ j ] = false ; } } for ( let j = 0 ; j < n ; j ++ ) { let isEndless = true ; for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( input [ i ] [ j ] == false ) isEndless = false ; col [ i ] [ j ] = isEndless ; } } for ( let i = 0 ; i < n ; i ++ ) { let isEndless = true ; for ( let j = n - 1 ; j >= 0 ; j -- ) { if ( input [ i ] [ j ] == false ) isEndless = false ; row [ i ] [ j ] = isEndless ; } } let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 1 ; j < n ; j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ; return ans ; } let input = [ [ true , false , true , true ] , [ false , true , true , true ] , [ true , true , true , true ] , [ false , true , true , false ] ] ; let n = 4 ; document . write ( countEndless ( input , n ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Boolean variables: isEndless
Javascript program:
function equilibrium ( arr , n ) { sum = 0 ; leftsum = 0 ; for ( let i = 0 ; i < n ; ++ i ) sum += arr [ i ] ; for ( let i = 0 ; i < n ; ++ i ) { sum -= arr [ i ] ; if ( leftsum == sum ) return i ; leftsum += arr [ i ] ; } return - 1 ; } arr = new Array ( - 7 , 1 , 5 , 2 , - 4 , 3 , 0 ) ; n = arr . length ; document . write ( " " + equilibrium ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: leftsum, sum
Iterator variables: i
Javascript program:
function sumOfSubstrings ( num ) { let n = num . length ; let sumofdigit = new Array ( n ) ; sumofdigit [ 0 ] = num [ 0 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; let res = sumofdigit [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { let numi = num [ i ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ; sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ; res += sumofdigit [ i ] ; } return res ; } let num = " " ; document . write ( sumOfSubstrings ( num ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function toDigit ( ch ) { return ( ch - ' ' ) ; } function sumOfSubStrings ( num ) { let n = num . length ; let prev = toDigit ( num [ 0 ] ) ; let res = prev ; let current = 0 ; for ( let i = 1 ; i < n ; i ++ ) { let numi = toDigit ( num [ i ] ) ; current = ( i + 1 ) * numi + 10 * prev ; res += current ; prev = current ; } return res ; } let num = " " ; document . write ( sumOfSubStrings ( num ) + " " ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Javascript program:
function equilibrium ( a , n ) { if ( n == 1 ) return ( 0 ) ; var forward = new Array ( 0 ) ; var rev = new Array ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( i ) { forward [ i ] = forward [ i - 1 ] + a [ i ] ; } else { forward [ i ] = a [ i ] ; } } for ( let i = n - 1 ; i > 0 ; i -- ) { if ( i <= n - 2 ) { rev [ i ] = rev [ i + 1 ] + a [ i ] ; } else { rev [ i ] = a [ i ] ; } } for ( let i = 0 ; i < n ; i ++ ) { if ( forward [ i ] == rev [ i ] ) { return i ; } } return - 1 ; } arr = new Array ( - 7 , 1 , 5 , 2 , - 4 , 3 , 0 ) ; n = arr . length ; document . write ( " " + equilibrium ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minCost ( N , K , M , a , b ) { var flag = true ; var map = new Map ( ) ; for ( var i = 0 ; i < M ; i ++ ) { map . set ( a [ i ] , b [ i ] ) ; if ( i == M - 1 && K < N - a [ i ] ) { flag = false ; break ; } else if ( i < M - 1 && K < a [ i + 1 ] - a [ i ] ) { flag = false ; break ; } } if ( ! flag ) { document . write ( - 1 ) ; return ; } var pq = [ ] ; var cost = 0 ; flag = false ; for ( var i = 0 ; i < N ; i ++ ) { if ( map . has ( i ) ) { var arr = [ i , map . get ( i ) , 0 ] ; pq . push ( arr ) ; } pq . sort ( ) ; while ( pq . length > 0 && pq [ pq . length - 1 ] [ 2 ] == K ) pq . pop ( ) ; if ( pq . length == 0 ) { flag = true ; break ; } var best_bunk = pq [ pq . length - 1 ] ; pq . pop ( ) ; cost += best_bunk [ 1 ] ; best_bunk [ 2 ] ++ ; pq . push ( best_bunk ) ; pq . sort ( ) ; } if ( flag ) { document . write ( - 1 + " " ) ; return ; } document . write ( cost + " " ) ; } var N = 10 , K = 3 , M = 4 ; var a = [ 0 , 1 , 4 , 6 ] ; var b = [ 5 , 2 , 2 , 4 ] ; minCost ( N , K , M , a , b ) ;

Index/key variables: i
Accumulator variables: cost, i
Iterator variables: i
Boolean variables: flag
Javascript program:
function max ( i , j ) { return ( i > j ) ? i : j ; } function unboundedKnapsack ( W , n , val , wt ) { let dp = new Array ( W + 1 ) ; dp . fill ( 0 ) ; for ( let i = 0 ; i <= W ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( wt [ j ] <= i ) { dp [ i ] = Math . max ( dp [ i ] , dp [ i - wt [ j ] ] + val [ j ] ) ; } } } return dp [ W ] ; } let W = 100 ; let val = [ 10 , 30 , 20 ] ; let wt = [ 5 , 10 , 15 ] ; let n = val . length ; document . write ( unboundedKnapsack ( W , n , val , wt ) ) ;

Index/key variables: W, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function ceilSearch ( arr , low , high , x ) { let i ; if ( x <= arr [ low ] ) return low ; for ( i = low ; i < high ; i ++ ) { if ( arr [ i ] == x ) return i ; if ( arr [ i ] < x && arr [ i + 1 ] >= x ) return i + 1 ; } return - 1 ; } let arr = [ 1 , 2 , 8 , 10 , 10 , 12 , 19 ] ; let n = arr . length ; let x = 3 ; let index = ceilSearch ( arr , 0 , n - 1 , x ) ; if ( index == - 1 ) document . write ( " " + x + " " ) ; else document . write ( " " + x + " " + arr [ index ] ) ;

Index/key variables: i, index, low
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSumSubarrayRemovingOneEle ( arr , n ) { let fw = [ ] ; let bw = [ ] ; let cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ; fw [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ; max_so_far = Math . max ( max_so_far , cur_max ) ; fw [ i ] = cur_max ; } cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; i -- ) { cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ; max_so_far = Math . max ( max_so_far , cur_max ) ; bw [ i ] = cur_max ; } let fans = max_so_far ; for ( let i = 1 ; i < n - 1 ; i ++ ) fans = Math . max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ; return fans ; } let arr = [ - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 ] ; let n = arr . length ; document . write ( maxSumSubarrayRemovingOneEle ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function ceilSearch ( arr , low , high , x ) { let mid ; if ( x <= arr [ low ] ) return low ; if ( x > arr [ high ] ) return - 1 ; mid = ( low + high ) / 2 ; if ( arr [ mid ] == x ) return mid ; else if ( arr [ mid ] < x ) { if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ; else return ceilSearch ( arr , mid + 1 , high , x ) ; } else { if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ; else return ceilSearch ( arr , low , mid - 1 , x ) ; } } let arr = [ 1 , 2 , 8 , 10 , 10 , 12 , 19 ] ; let n = arr . length ; let x = 20 ; let index = ceilSearch ( arr , 0 , n - 1 , x ) ; if ( index == - 1 ) { document . write ( ` ${ x } ` ) ; } else { document . write ( ` ${ x } ${ arr [ index ] } ` ) ; }

Index/key variables: high, index, low, mid
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } function getHeight ( Node ) { if ( Node == null ) return 0 ; else { let lHeight = getHeight ( Node . left ) ; let rHeight = getHeight ( Node . right ) ; if ( lHeight > rHeight ) return ( lHeight + 1 ) ; else return ( rHeight + 1 ) ; } } function getTotalHeight ( root ) { if ( root == null ) return 0 ; return getTotalHeight ( root . left ) + getHeight ( root ) + getTotalHeight ( root . right ) ; } let root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; document . write ( " " + getTotalHeight ( root ) ) ;

Class/struct names: Node
Javascript program:
function maxAverageOfPath ( cost , N ) { let dp = new Array ( N + 1 ) ; for ( let i = 0 ; i < N + 1 ; i ++ ) { dp [ i ] = new Array ( N + 1 ) ; for ( let j = 0 ; j < N + 1 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ; for ( let j = 1 ; j < N ; j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ; for ( let i = 1 ; i < N ; i ++ ) for ( let j = 1 ; j < N ; j ++ ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ; return dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ; } let cost = [ [ 1 , 2 , 3 ] , [ 6 , 5 , 4 ] , [ 7 , 3 , 9 ] ] ; document . write ( maxAverageOfPath ( cost , 3 ) ) ;

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