dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
MAX = 10000 ; prefix = new Array ( MAX + 1 ) ; function buildPrefix ( ) { prime = new Array ( MAX + 1 ) ; prime . fill ( true ) ; for ( var p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( var i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } prefix [ 0 ] = prefix [ 1 ] = 0 ; for ( var p = 2 ; p <= MAX ; p ++ ) { prefix [ p ] = prefix [ p - 1 ] ; if ( prime [ p ] ) prefix [ p ] += p ; } } function sumPrimeRange ( L , R ) { buildPrefix ( ) ; return prefix [ R ] - prefix [ L - 1 ] ; } var L = 10 , R = 20 ; document . write ( sumPrimeRange ( L , R ) + " " ) ;

Index/key variables: R, i, p
Accumulator variables: i, p
Iterator variables: i, p
Javascript program:
function repeatedSum ( n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } function repeatedProduct ( n ) { var prod = 1 ; while ( n > 0 prod > 9 ) { if ( n == 0 ) { n = prod ; prod = 1 ; } prod *= n % 10 ; n = parseInt ( n / 10 ) ; } return prod ; } function maxSumProduct ( N ) { if ( N < 10 ) return N ; return Math . max ( repeatedSum ( N ) , repeatedProduct ( N ) ) ; } var n = 631 ; document . write ( maxSumProduct ( n ) ) ;

Accumulator variables: prod
Javascript program:
function max_value ( array , M , K , N ) { var time = Array ( M ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { time [ array [ i ] [ 0 ] ] = array [ i ] [ 1 ] ; } var dp = Array . from ( Array ( M ) , ( ) => Array ( 2 ) ) ; dp [ 0 ] [ 0 ] = 0 ; dp [ 0 ] [ 1 ] = time [ 0 ] ; for ( var i = 1 ; i < M ; i ++ ) { dp [ i ] [ 0 ] = Math . max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) ; dp [ i ] [ 1 ] = time [ i ] ; if ( i - K >= 0 ) { dp [ i ] [ 1 ] += Math . max ( dp [ i - K ] [ 0 ] , dp [ i - K ] [ 1 ] ) ; } } return Math . max ( dp [ M - 1 ] [ 0 ] , dp [ M - 1 ] [ 1 ] ) ; } var array = [ [ 0 , 10 ] , [ 4 , 110 ] , [ 5 , 30 ] ] ; var N = 3 ; var K = 4 ; var M = 6 ; document . write ( max_value ( array , M , K , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let digits = [ ] ; let vis = new Array ( 170 ) ; vis . fill ( false ) ; let dp = new Array ( 19 ) ; for ( let i = 0 ; i < 19 ; i ++ ) { dp [ i ] = new Array ( 19 ) ; for ( let j = 0 ; j < 19 ; j ++ ) { dp [ i ] [ j ] = new Array ( 2 ) ; for ( let k = 0 ; k < 2 ; k ++ ) { dp [ i ] [ j ] [ k ] = new Array ( 170 ) ; for ( let l = 0 ; l < 170 ; l ++ ) { dp [ i ] [ j ] [ k ] [ l ] = 0 ; } } } } function ConvertIntoDigit ( n ) { while ( n > 0 ) { let dig = n % 10 ; digits . push ( dig ) ; n = parseInt ( n / 10 , 10 ) ; } digits . reverse ( ) ; } function solve ( idx , k , tight , sum ) { if ( idx == digits . length && k == 0 && sum % 2 == 1 ) { if ( ! vis [ sum ] ) { vis [ sum ] = true ; return 1 ; } return 0 ; } if ( idx > digits . length ) { return 0 ; } if ( dp [ idx ] [ k ] [ tight ] [ sum ] > 0 ) { return dp [ idx ] [ k ] [ tight ] [ sum ] ; } let j ; if ( idx < digits . length && tight == 0 ) { j = digits [ idx ] ; } else { j = 9 ; } let cnt = 0 ; for ( let i = ( k > 0 ? 0 : 1 ) ; i <= j ; i ++ ) { let newtight = tight ; if ( i < j ) { newtight = 1 ; } if ( i == 0 ) cnt += solve ( idx + 1 , k - 1 , newtight , sum ) ; else cnt += solve ( idx + 1 , k , newtight , sum + i ) ; } dp [ idx ] [ k ] [ tight ] [ sum ] = cnt ; return dp [ idx ] [ k ] [ tight ] [ sum ] ; } let N , k ; N = 169 ; k = 2 ; ConvertIntoDigit ( N ) ; k = digits . length - k ; document . write ( solve ( 0 , k , 0 , 0 ) ) ;

Index/key variables: i, idx, j, k, l, sum, tight
Accumulator variables: cnt, i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
function countSubsets ( N ) { if ( N <= 2 ) return N ; if ( N == 3 ) return 2 ; var DP = Array ( N + 1 ) . fill ( 0 ) ; DP [ 0 ] = 0 ; DP [ 1 ] = 1 ; DP [ 2 ] = 2 ; DP [ 3 ] = 2 ; for ( i = 4 ; i <= N ; i ++ ) { DP [ i ] = DP [ i - 2 ] + DP [ i - 3 ] ; } return DP [ N ] ; } var N = 20 ; document . write ( countSubsets ( N ) ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
var dp = Array . from ( Array ( 500 ) , ( ) => Array ( 500 ) ) ; function CountSets ( x , pos ) { if ( x <= 0 ) { if ( pos == 0 ) return 1 ; else return 0 ; } if ( pos == 0 ) return 1 ; if ( dp [ x ] [ pos ] != - 1 ) return dp [ x ] [ pos ] ; var answer = CountSets ( x - 1 , pos ) + CountSets ( x - 2 , pos - 1 ) ; return dp [ x ] [ pos ] = answer ; } function CountOrderedSets ( n ) { var factorial = Array ( 10000 ) . fill ( 0 ) ; factorial [ 0 ] = 1 ; for ( var i = 1 ; i < 10000 ; i ++ ) factorial [ i ] = factorial [ i - 1 ] * i ; var answer = 0 ; dp = Array . from ( Array ( 500 ) , ( ) => Array ( 500 ) . fill ( - 1 ) ) ; for ( var i = 1 ; i <= n ; i ++ ) { var sets = CountSets ( n , i ) * factorial [ i ] ; answer = answer + sets ; } return answer ; } var N = 3 ; document . write ( CountOrderedSets ( N ) ) ;

Index/key variables: i, pos, x
Accumulator variables: i
Iterator variables: i
Javascript program:
function numberOfArithmeticSequences ( L , N ) { if ( N <= 2 ) return 0 ; var count = 0 ; var res = 0 ; for ( var i = 2 ; i < N ; ++ i ) { if ( L [ i ] - L [ i - 1 ] == L [ i - 1 ] - L [ i - 2 ] ) { ++ count ; } else { count = 0 ; } res += count ; } return res ; } var L = [ 1 , 3 , 5 , 6 , 7 , 8 ] ; var N = L . length ; document . write ( numberOfArithmeticSequences ( L , N ) ) ;

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Javascript program:
function CountOfTriplets ( a , n ) { let answer = 0 ; let x = 0 ; let count = new Array ( 100005 ) ; let ways = new Array ( 100005 ) ; count . fill ( 0 ) ; ways . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { x ^= a [ i ] ; answer += count [ x ] * i - ways [ x ] ; count [ x ] ++ ; ways [ x ] = ways [ x ] + i + 1 ; } return answer ; } let Arr = [ 3 , 6 , 12 , 8 , 6 , 2 , 1 , 5 ] ; let N = Arr . length ; document . write ( CountOfTriplets ( Arr , N ) ) ;

Index/key variables: i, x
Accumulator variables: answer, i, x
Iterator variables: i
Javascript program:
var dp = Array . from ( Array ( 5000 ) , ( ) => Array ( ( 1 << 10 ) + 5 ) . fill ( - 1 ) ) ; function getmask ( val ) { var mask = 0 ; if ( val == 0 ) return 1 ; while ( val ) { var d = val % 10 ; mask |= ( 1 << d ) ; val = parseInt ( val / 10 ) ; } return mask ; } function countWays ( pos , mask , a , n ) { if ( pos == n ) return ( mask > 0 ? 1 : 0 ) ; if ( dp [ pos ] [ mask ] != - 1 ) return dp [ pos ] [ mask ] ; var count = 0 ; count = count + countWays ( pos + 1 , mask , a , n ) ; if ( ( getmask ( a [ pos ] ) & mask ) == 0 ) { var new_mask = ( mask | ( getmask ( a [ pos ] ) ) ) ; count = count + countWays ( pos + 1 , new_mask , a , n ) ; } return dp [ pos ] [ mask ] = count ; } function numberOfSubarrays ( a , n ) { dp = Array . from ( Array ( 5000 ) , ( ) => Array ( ( 1 << 10 ) + 5 ) . fill ( - 1 ) ) ; return countWays ( 0 , 0 , a , n ) ; } var N = 4 ; var A = [ 1 , 12 , 23 , 34 ] ; document . write ( numberOfSubarrays ( A , N ) ) ;

Index/key variables: mask, pos
Accumulator variables: mask
Javascript program:
let fib = [ ] ; class node { constructor ( data ) { this . left = null ; this . right = null ; this . data = data ; } } ; function newNode ( data ) { let temp = new node ( data ) ; return temp ; } function height ( root ) { if ( root == null ) return 0 ; return ( Math . max ( height ( root . left ) , height ( root . right ) ) + 1 ) ; } function FibonacciSeries ( n ) { fib . push ( 0 ) ; fib . push ( 1 ) ; for ( let i = 2 ; i < n ; i ++ ) fib . push ( fib [ i - 1 ] + fib [ i - 2 ] ) ; } function CountPathUtil ( root , i , count ) { if ( root == null || ! ( fib [ i ] == root . data ) ) { return count ; } if ( root . left != null && root . right != null ) { count ++ ; } count = CountPathUtil ( root . left , i + 1 , count ) ; return CountPathUtil ( root . right , i + 1 , count ) ; } function CountPath ( root ) { let ht = height ( root ) ; FibonacciSeries ( ht ) ; document . write ( CountPathUtil ( root , 0 , 0 ) ) ; } let root = newNode ( 0 ) ; root . left = newNode ( 1 ) ; root . right = newNode ( 1 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 4 ) ; root . right . right = newNode ( 1 ) ; root . right . right . left = newNode ( 2 ) ; CountPath ( root ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: node
Javascript program:
function maximumOccurrence ( s ) { var n = s . length ; var freq = Array ( 26 ) . fill ( 0 ) ; var dp = Array ( 26 ) . fill ( ) . map ( ( ) => Array ( 26 ) . fill ( 0 ) ) ; for ( var i = 0 ; i < n ; i ++ ) { var c = ( s . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ) ; for ( var j = 0 ; j < 26 ; j ++ ) dp [ j ] += freq [ j ] ; freq ++ ; } var answer = Number . MIN_VALUE ; for ( var i = 0 ; i < 26 ; i ++ ) answer = Math . max ( answer , freq [ i ] ) ; for ( var i = 0 ; i < 26 ; i ++ ) { for ( var j = 0 ; j < 26 ; j ++ ) { answer = Math . max ( answer , dp [ i ] [ j ] ) ; } } return answer ; } var s = " " ; document . write ( maximumOccurrence ( s ) ) ;

Index/key variables: i, j
Accumulator variables: freq, i, j
Iterator variables: i, j
Javascript program:
var mod = 1000000007 ; var dp = Array . from ( Array ( 1005 ) , ( ) => Array ( 105 ) ) ; for ( var i = 0 ; i < 1005 ; i ++ ) { for ( var j = 0 ; j < 105 ; j ++ ) { dp [ i ] [ j ] = Array ( 2 ) . fill ( - 1 ) ; } } var powers = Array ( 1005 ) ; var powersModk = Array ( 1005 ) ; function calculate ( pos , rem , z , k , n ) { if ( rem == 0 && z ) { if ( pos != n ) return ( powers [ n - pos - 1 ] * 9 ) % mod ; else return 1 ; } if ( pos == n ) return 0 ; if ( dp [ pos ] [ rem ] [ z ] != - 1 ) return dp [ pos ] [ rem ] [ z ] ; var count = 0 ; for ( var i = 0 ; i < 10 ; i ++ ) { if ( i == 0 ) count = ( count + ( calculate ( pos + 1 , ( rem + ( i * powersModk [ pos ] ) % k ) % k , z , k , n ) ) ) % mod ; else count = ( count + ( calculate ( pos + 1 , ( rem + ( i * powersModk [ pos ] ) % k ) % k , 1 , k , n ) ) ) % mod ; } return dp [ pos ] [ rem ] [ z ] = count ; } function countNumbers ( n , k ) { var st = 1 ; for ( var i = 0 ; i <= n ; i ++ ) { powers [ i ] = st ; st *= 10 ; st %= mod ; } st = 1 ; for ( var i = 0 ; i <= n ; i ++ ) { powersModk [ i ] = st ; st *= 10 ; st %= mod ; } return calculate ( 0 , 0 , 0 , k , n ) ; } var N = 2 ; var K = 2 ; document . write ( countNumbers ( N , K ) ) ;

Index/key variables: i, j, pos, rem, z
Accumulator variables: i, j, st
Iterator variables: i, j
Javascript program:
let inf = 100000000 ; function smPath ( s , d , ed , n , k ) { let dis = new Array ( n + 1 ) ; for ( let i = 0 ; i < ( n + 1 ) ; i ++ ) { dis [ i ] = inf ; } dis [ s ] = 0 ; for ( let i = 0 ; i < k ; i ++ ) { let dis1 = new Array ( n + 1 ) ; for ( let i = 0 ; i < ( n + 1 ) ; i ++ ) { dis1 [ i ] = inf ; } for ( let it = 0 ; it < ed . length ; it ++ ) dis1 [ ed [ it ] [ 1 ] ] = Math . min ( dis1 [ ed [ it ] [ 1 ] ] , dis [ ed [ it ] [ 0 ] ] + ed [ it ] [ 2 ] ) ; document . write ( ) for ( let j = 0 ; j <= n ; j ++ ) dis [ j ] = dis1 [ j ] ; } if ( dis [ d ] == inf ) return - 1 ; else return dis [ d ] ; } let n = 4 ; let ed = [ [ 0 , 1 , 10 ] , [ 0 , 2 , 3 ] , [ 0 , 3 , 2 ] , [ 1 , 3 , 7 ] , [ 2 , 3 , 7 ] ] ; let s = 0 , d = 3 ; let k = 2 ; document . write ( smPath ( s , d , ed , n , k ) ) ;

Index/key variables: d, i, it, j, s
Accumulator variables: i, it, j
Iterator variables: i, it, j
Javascript program:
var inf = 1000000000 ; function bellman ( s , d , ed , n ) { if ( s == d ) return 0 ; var dis = Array ( n + 1 ) . fill ( inf ) ; dis [ s ] = 1 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { for ( var j = 0 ; j < ed . length ; j ++ ) { dis [ ed [ j ] [ 0 ] [ 1 ] ] = Math . min ( dis [ ed [ j ] [ 0 ] [ 1 ] ] , dis [ ed [ j ] [ 0 ] [ 0 ] ] * ed [ j ] [ 1 ] ) ; } } for ( var it in ed ) { if ( dis [ it [ 0 ] [ 1 ] ] > dis [ it [ 0 ] [ 0 ] ] * it [ 1 ] ) return - 2 ; } if ( dis [ d ] == inf ) return - 1 ; else return dis [ d ] ; } var n = 3 ; var ed ; ed = [ [ [ 1 , 2 ] , 0.5 ] , [ [ 1 , 3 ] , 1.9 ] , [ [ 2 , 3 ] , 3 ] ] ; var s = 1 , d = 3 ; var get = bellman ( s , d , ed , n ) ; if ( get == - 2 ) document . write ( " " ) ; else document . write ( get ) ;

Index/key variables: d, j, s
Accumulator variables: i, j
Iterator variables: i, it, j
Javascript program:
function maxLengthSquare ( row , column , arr , k ) { let sum = new Array ( ) ; [ row + 1 ] [ column + 1 ] ; for ( let i = 0 ; i < row + 1 ; i ++ ) { let temp = new Array ( ) ; for ( let j = 0 ; j < column + 1 ; j ++ ) { temp . push ( [ ] ) } sum . push ( temp ) } for ( let i = 1 ; i <= row ; i ++ ) for ( let j = 0 ; j <= column ; j ++ ) sum [ i ] [ j ] = 0 ; let cur_max = 1 ; let max = 0 ; for ( let i = 1 ; i <= row ; i ++ ) { for ( let j = 1 ; j <= column ; j ++ ) { sum [ i ] [ j ] = sum [ i - 1 ] [ j ] + sum [ i ] [ j - 1 ] + arr [ i - 1 ] [ j - 1 ] - sum [ i - 1 ] [ j - 1 ] ; if ( i >= cur_max && j >= cur_max && sum [ i ] [ j ] - sum [ i - cur_max ] [ j ] - sum [ i ] [ j - cur_max ] + sum [ i - cur_max ] [ j - cur_max ] <= k ) { max = cur_max ++ ; } } } return max ; } let row = 4 , column = 4 ; let matrix = [ [ 1 , 1 , 1 , 1 ] , [ 1 , 0 , 0 , 0 ] , [ 1 , 0 , 0 , 0 ] , [ 1 , 0 , 0 , 0 ] ] ; let k = 6 ; let ans = maxLengthSquare ( row , column , matrix , k ) ; document . write ( ans ) ;

Index/key variables: i, j
Accumulator variables: cur_max, i, j
Iterator variables: i, j
Javascript program:
let N = 101 ; let mod = 1e9 + 7 ; let exactsum = new Array ( N ) ; let exactnum = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { exactsum [ i ] = new Array ( N ) ; exactnum [ i ] = new Array ( N ) ; for ( let j = 0 ; j < N ; j ++ ) { exactsum [ i ] [ j ] = new Array ( N ) ; exactnum [ i ] [ j ] = new Array ( N ) ; for ( let k = 0 ; k < N ; k ++ ) { exactsum [ i ] [ j ] [ k ] = 0 ; exactnum [ i ] [ j ] [ k ] = 0 ; } } } function getSum ( x , y , z ) { let ans = 0 ; exactnum [ 0 ] [ 0 ] [ 0 ] = 1 ; for ( let i = 0 ; i <= x ; ++ i ) { for ( let j = 0 ; j <= y ; ++ j ) { for ( let k = 0 ; k <= z ; ++ k ) { if ( i > 0 ) { exactsum [ i ] [ j ] [ k ] += ( exactsum [ i - 1 ] [ j ] [ k ] * 10 + 4 * exactnum [ i - 1 ] [ j ] [ k ] ) % mod ; exactnum [ i ] [ j ] [ k ] += exactnum [ i - 1 ] [ j ] [ k ] % mod ; } if ( j > 0 ) { exactsum [ i ] [ j ] [ k ] += ( exactsum [ i ] [ j - 1 ] [ k ] * 10 + 5 * exactnum [ i ] [ j - 1 ] [ k ] ) % mod ; exactnum [ i ] [ j ] [ k ] += exactnum [ i ] [ j - 1 ] [ k ] % mod ; } if ( k > 0 ) { exactsum [ i ] [ j ] [ k ] += ( exactsum [ i ] [ j ] [ k - 1 ] * 10 + 6 * exactnum [ i ] [ j ] [ k - 1 ] ) % mod ; exactnum [ i ] [ j ] [ k ] += exactnum [ i ] [ j ] [ k - 1 ] % mod ; } ans += exactsum [ i ] [ j ] [ k ] % mod ; ans %= mod ; } } } return ans ; } let x = 1 , y = 1 , z = 1 ; document . write ( getSum ( x , y , z ) % mod ) ;

Index/key variables: i, j, k
Accumulator variables: ans, i, j, k
Iterator variables: i, j, k
Javascript program:
function findMax ( a , n ) { var dp = Array ( n ) . fill ( ) . map ( ( ) => Array ( 2 ) . fill ( 0 ) ) ; var i , j ; for ( i = 0 ; i < n ; i ++ ) for ( j = 0 ; j < 2 ; j ++ ) dp [ i ] [ j ] = 0 ; dp [ 0 ] [ 0 ] = a [ 0 ] + a [ 1 ] ; dp [ 0 ] [ 1 ] = a [ 0 ] * a [ 1 ] ; for ( i = 1 ; i <= n - 2 ; i ++ ) { dp [ i ] [ 0 ] = Math . max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + a [ i + 1 ] ; dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] - a [ i ] + a [ i ] * a [ i + 1 ] ; } document . write ( Math . max ( dp [ n - 2 ] [ 0 ] , dp [ n - 2 ] [ 1 ] ) ) ; } var arr = [ 5 , - 1 , - 5 , - 3 , 2 , 9 , - 4 ] ; findMax ( arr , 7 ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function sum ( arr , l , r ) { let s = 0 ; for ( let i = l ; i <= r ; i ++ ) { s += arr [ i ] ; } return s ; } let dp = new Array ( 101 ) ; for ( let i = 0 ; i < 101 ; i ++ ) { dp [ i ] = new Array ( 101 ) ; for ( let j = 0 ; j < 101 ; j ++ ) { dp [ i ] [ j ] = new Array ( 101 ) ; for ( let k = 0 ; k < 101 ; k ++ ) { dp [ i ] [ j ] [ k ] = 0 ; } } } function solve ( arr , l , r , k ) { if ( r - l + 1 <= k ) return sum ( arr , l , r ) ; if ( dp [ l ] [ r ] [ k ] != 0 ) return dp [ l ] [ r ] [ k ] ; let sum_ = sum ( arr , l , r ) ; let len_r = ( r - l + 1 ) - k ; let len = ( r - l + 1 ) ; let ans = 0 ; for ( let i = 0 ; i < len - len_r + 1 ; i ++ ) { let sum_sub = sum ( arr , i + l , i + l + len_r - 1 ) ; ans = Math . max ( ans , ( sum_ - sum_sub ) + ( sum_sub - solve ( arr , i + l , i + l + len_r - 1 , k ) ) ) ; } dp [ l ] [ r ] [ k ] = ans ; return ans ; } let arr = [ 10 , 15 , 20 , 9 , 2 , 5 ] , k = 2 ; let n = arr . length ; document . write ( solve ( arr , 0 , n - 1 , k ) ) ;

Index/key variables: i, j, k, l, r
Accumulator variables: i, j, k, s
Iterator variables: i, j, k
Javascript program:
let MAXI = 50 ; let dp = new Array ( MAXI ) ; let n , m ; let INT_MAX = Number . MAX_VALUE ; function minDifference ( x , y , k , b , c ) { if ( x >= n y >= m ) return INT_MAX ; if ( x == n - 1 && y == m - 1 ) { let diff = b [ x ] [ y ] - c [ x ] [ y ] ; return Math . min ( Math . abs ( k - diff ) , Math . abs ( k + diff ) ) ; } let ans = dp [ x ] [ y ] [ k ] ; if ( ans != - 1 ) return ans ; ans = INT_MAX ; let diff = b [ x ] [ y ] - c [ x ] [ y ] ; ans = Math . min ( ans , minDifference ( x + 1 , y , Math . abs ( k + diff ) , b , c ) ) ; ans = Math . min ( ans , minDifference ( x , y + 1 , Math . abs ( k + diff ) , b , c ) ) ; ans = Math . min ( ans , minDifference ( x + 1 , y , Math . abs ( k - diff ) , b , c ) ) ; ans = Math . min ( ans , minDifference ( x , y + 1 , Math . abs ( k - diff ) , b , c ) ) ; return ans ; } n = 2 ; m = 2 ; let b = [ [ 1 , 4 ] , [ 2 , 4 ] ] ; let c = [ [ 3 , 2 ] , [ 3 , 1 ] ] ; for ( let i = 0 ; i < MAXI ; i ++ ) { dp [ i ] = new Array ( MAXI ) ; for ( let j = 0 ; j < MAXI ; j ++ ) { dp [ i ] [ j ] = new Array ( MAXI * MAXI ) ; for ( let k = 0 ; k < MAXI * MAXI ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } document . write ( minDifference ( 0 , 0 , 0 , b , c ) ) ;

Index/key variables: i, j, k, x, y
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function longest_subseq ( n , k , s ) { let dp = new Array ( n ) ; let max_length = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { max_length [ i ] = 0 ; dp [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { let curr = s [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; let lower = Math . max ( 0 , curr - k ) ; let upper = Math . min ( 25 , curr + k ) ; for ( let j = lower ; j < upper + 1 ; j ++ ) { dp [ i ] = Math . max ( dp [ i ] , max_length [ j ] + 1 ) ; } max_length [ curr ] = Math . max ( dp [ i ] , max_length [ curr ] ) ; } let ans = 0 ; ans = Math . max ( ... dp ) return ans ; } let s = " " ; let n = s . length ; let k = 3 ; document . write ( longest_subseq ( n , k , s ) ) ;

Index/key variables: curr, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function areAllNegative ( arr ) { let n = arr . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) return false ; } return true ; } function getRightToLeftKadane ( arr ) { let max_so_far = 0 , max_ending_here = 0 ; let size = arr . length ; let new_arr = new Array ( size ) ; for ( let i = 0 ; i < size ; i ++ ) new_arr [ i ] = arr [ i ] ; for ( let i = size - 1 ; i >= 0 ; i -- ) { max_ending_here = max_ending_here + new_arr [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; else if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; new_arr [ i ] = max_so_far ; } return new_arr ; } function getPrefixSum ( arr ) { let n = arr . length ; let new_arr = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) new_arr [ i ] = arr [ i ] ; for ( let i = 1 ; i < n ; i ++ ) new_arr [ i ] = new_arr [ i - 1 ] + new_arr [ i ] ; return new_arr ; } function maxSumSubArr ( a ) { let max_so_far = 0 , max_ending_here = 0 ; let n = a . length ; for ( let i = 0 ; i < n ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; else if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } return max_so_far ; } function maxSumSubWithOp ( arr ) { let kadane_r_to_l = getRightToLeftKadane ( arr ) ; let size = arr . length ; let prefixSum = getPrefixSum ( arr ) ; for ( let i = 1 ; i < size ; i ++ ) { prefixSum [ i ] = Math . max ( prefixSum [ i - 1 ] , prefixSum [ i ] ) ; } let max_subarray_sum = 0 ; for ( let i = 0 ; i < size - 1 ; i ++ ) { max_subarray_sum = Math . max ( max_subarray_sum , prefixSum [ i ] + kadane_r_to_l [ i + 1 ] ) ; } return max_subarray_sum ; } function maxSum ( arr , size ) { if ( areAllNegative ( arr ) ) { let mx = - 1000000000 ; for ( let i = 0 ; i < size ; i ++ ) { if ( arr [ i ] > mx ) mx = arr [ i ] ; } return mx ; } let resSum = maxSumSubArr ( arr ) ; resSum = Math . max ( resSum , maxSumSubWithOp ( arr ) ) ; let reverse_arr = new Array ( size ) ; for ( let i = 0 ; i < size ; i ++ ) reverse_arr [ size - 1 - i ] = arr [ i ] ; resSum = Math . max ( resSum , maxSumSubWithOp ( reverse_arr ) ) ; return resSum ; } let arr = [ - 9 , 21 , 24 , 24 , - 51 , - 6 , 17 , - 42 , - 39 , 33 ] ; let size = arr . length ; document . write ( maxSum ( arr , size ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function max_sum ( a , n ) { var dp = Array ( n + 1 ) . fill ( ) . map ( ( ) => Array ( 2 ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = 0 ; dp [ 0 ] [ 1 ] = - 999999 ; for ( i = 0 ; i <= n - 1 ; i ++ ) { dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 0 ] + a [ i ] , dp [ i ] [ 1 ] - a [ i ] ) ; dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] - a [ i ] , dp [ i ] [ 1 ] + a [ i ] ) ; } return dp [ n ] [ 0 ] ; } var a = [ - 10 , 5 , - 4 ] ; var n = a . length ; document . write ( max_sum ( a , n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
let MOD = 1000000007 ; function number_of_ways ( arr , n , k ) { if ( k == 1 ) return 1 ; let dp = new Array ( k + 1 ) ; let i ; for ( i = 0 ; i < k + 1 ; i ++ ) dp [ i ] = - 1 ; for ( i = 0 ; i < n ; i ++ ) dp [ arr [ i ] ] = 0 ; dp [ 0 ] = 1 ; dp [ 1 ] = ( dp [ 1 ] == - 1 ) ? 1 : dp [ 1 ] ; for ( i = 2 ; i <= k ; ++ i ) { if ( dp [ i ] == 0 ) continue ; dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ; dp [ i ] %= MOD ; } return dp [ k ] ; } let arr = [ 3 ] ; let n = arr . length ; let k = 6 ; document . write ( number_of_ways ( arr , n , k ) ) ;

Index/key variables: i, k
Accumulator variables: i
Iterator variables: i
Javascript program:
function count ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function findSetBits ( n ) { for ( let i = 0 ; i <= n ; i ++ ) document . write ( count ( i ) + " " ) ; } let n = 5 ; findSetBits ( n ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countWays ( n ) { let a = [ ] ; let i = 1 ; while ( i <= n ) a . push ( i ++ ) ; let ways = 0 ; do { let flag = ( a [ 0 ] == 1 ) ; for ( let j = 1 ; j < n ; j ++ ) { if ( Math . abs ( a [ j ] - a [ j - 1 ] ) > 2 ) flag = false ; } if ( flag ) ways ++ ; } while ( next_permutation ( a ) ) ; return ways ; } function next_permutation ( p ) { for ( let a = p . length - 2 ; a >= 0 ; -- a ) { if ( p [ a ] < p [ a + 1 ] ) { for ( let b = p . length - 1 ; ; -- b ) { if ( p [ b ] > p [ a ] ) { let t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . length - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } } } } return false ; } let n = 6 ; document . write ( countWays ( n ) ) ;

Index/key variables: a, b, j
Accumulator variables: i, j, ways
Iterator variables: a, b, j
Boolean variables: flag
Javascript program:
function countWays ( n ) { let dp = new Array ( n + 1 ) ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; dp [ 2 ] = 1 ; for ( let i = 3 ; i <= n ; i ++ ) { dp [ i ] = dp [ i - 1 ] + dp [ i - 3 ] + 1 ; } return dp [ n ] ; } let n = 6 ; document . write ( countWays ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function NumberOfShortestPaths ( n , m ) { var a = Array ( n ) . fill ( ) . map ( ( ) => Array ( m ) . fill ( 0 ) ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { for ( j = 0 ; j < m ; j ++ ) { if ( j == 0 i == n - 1 ) a [ i ] [ j ] = 1 ; else a [ i ] [ j ] = a [ i ] [ j - 1 ] + a [ i + 1 ] [ j ] ; } } for ( var i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { document . write ( a [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } var n = 5 , m = 2 ; NumberOfShortestPaths ( n , m ) ;

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