dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function precompute ( arr , n , pre ) { for ( let i = 0 ; i < n ; i ++ ) pre [ i ] = 0 ; pre [ n - 1 ] = arr [ n - 1 ] * ( Math . pow ( 2 , 0 ) ) ; for ( let i = n - 2 ; i >= 0 ; i -- ) pre [ i ] = pre [ i + 1 ] + arr [ i ] * ( 1 << ( n - 1 - i ) ) ; } function decimalOfSubarr ( arr , l , r , n , pre ) { if ( r != n - 1 ) return ( pre [ l ] - pre [ r + 1 ] ) / ( 1 << ( n - 1 - r ) ) ; return pre [ l ] / ( 1 << ( n - 1 - r ) ) ; } let arr = [ 1 , 0 , 1 , 0 , 1 , 1 ] ; let n = arr . length ; let pre = new Array ( n ) precompute ( arr , n , pre ) ; document . write ( decimalOfSubarr ( arr , 2 , 4 , n , pre ) + " " ) ; document . write ( decimalOfSubarr ( arr , 4 , 5 , n , pre ) ) ;

Index/key variables: i, l
Accumulator variables: i
Iterator variables: i
Javascript program:
function answerQuery ( a , n , l , r ) { var count = 0 ; l = l - 1 ; for ( i = l ; i < r ; i ++ ) { var element = a [ i ] ; var divisors = 0 ; for ( j = l ; j < r ; j ++ ) { if ( a [ j ] % a [ i ] == 0 ) divisors ++ ; else break ; } if ( divisors == ( r - l ) ) count ++ ; } return count ; } var a = [ 1 , 2 , 3 , 5 ] ; var n = a . length ; var l = 1 , r = 4 ; document . write ( answerQuery ( a , n , l , r ) + " " ) ; l = 2 ; r = 4 ; document . write ( answerQuery ( a , n , l , r ) ) ;

Index/key variables: i, j
Accumulator variables: count, divisors, i, j
Iterator variables: i, j
Javascript program:
function minBinary ( n ) { var digit = Array ( 10 ) . fill ( 0 ) ; var len = 0 ; while ( n > 0 ) { digit [ len ++ ] = n % 10 ; n = parseInt ( n / 10 ) ; } digit = reverse ( digit , 0 , len - 1 ) ; var ans = 0 ; for ( i = 0 ; i < len ; i ++ ) { ans = Math . max ( ans , digit [ i ] ) ; } document . write ( " " + " " + ans + " " ) ; for ( i = 1 ; i <= ans ; i ++ ) { var num = 0 ; for ( j = 0 ; j < len ; j ++ ) { if ( digit [ j ] > 0 ) { num = num * 10 + 1 ; digit [ j ] -- ; } else { num *= 10 ; } } document . write ( num + " " ) ; } } function reverse ( str , start , end ) { var temp ; while ( start <= end ) { temp = str [ start ] ; str [ start ] = str [ end ] ; str [ end ] = temp ; start ++ ; end -- ; } return str ; } var n = 564 ; minBinary ( n ) ;

Index/key variables: end, i, j, start
Accumulator variables: end, i, j, len, num, start
Iterator variables: i, j
Javascript program:
const MAX = 2147483647 ; let one = new Array ( 100001 ) ; for ( let i = 0 ; i < 100001 ; i ++ ) one [ i ] = new Array ( 32 ) ; function make_prefix ( A , n ) { for ( let j = 0 ; j < 32 ; j ++ ) one [ 0 ] [ j ] = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { let a = A [ i - 1 ] ; for ( let j = 0 ; j < 32 ; j ++ ) { let x = Math . pow ( 2 , j ) ; if ( a & x ) one [ i ] [ j ] = 1 + one [ i - 1 ] [ j ] ; else one [ i ] [ j ] = one [ i - 1 ] [ j ] ; } } } function Solve ( L , R ) { let l = L , r = R ; let tot_bits = r - l + 1 ; let X = MAX ; for ( let i = 0 ; i < 31 ; i ++ ) { let x = one [ r ] [ i ] - one [ l - 1 ] [ i ] ; if ( x >= tot_bits - x ) { let ith_bit = Math . pow ( 2 , i ) ; X = X ^ ith_bit ; } } return X ; } let n = 5 , q = 3 ; let A = [ 210 , 11 , 48 , 22 , 133 ] ; let L = [ 1 , 4 , 2 ] , R = [ 3 , 14 , 4 ] ; make_prefix ( A , n ) ; for ( let j = 0 ; j < q ; j ++ ) document . write ( Solve ( L [ j ] , R [ j ] ) + " " ) ;

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function type1 ( arr , start , limit ) { for ( let i = start ; i <= limit ; i ++ ) arr [ i ] ++ ; } function type2 ( arr , query , start , limit ) { for ( let i = start ; i <= limit ; i ++ ) { if ( query [ i ] [ 0 ] == 1 ) type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; else if ( query [ i ] [ 0 ] == 2 ) type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; } } let n = 5 , m = 5 ; let arr = new Array ( n + 1 ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = 0 ; } let temp = [ 1 , 1 , 2 , 1 , 4 , 5 , 2 , 1 , 2 , 2 , 1 , 3 , 2 , 3 , 4 ] ; let query = new Array ( 6 ) ; for ( let i = 0 ; i < 6 ; i ++ ) { query [ i ] = new Array ( 4 ) ; for ( let j = 0 ; j < 4 ; j ++ ) { query [ i ] [ j ] = 0 ; } } let j = 0 ; for ( let i = 1 ; i <= m ; i ++ ) { query [ i ] [ 0 ] = temp [ j ++ ] ; query [ i ] [ 1 ] = temp [ j ++ ] ; query [ i ] [ 2 ] = temp [ j ++ ] ; } for ( let i = 1 ; i <= m ; i ++ ) if ( query [ i ] [ 0 ] == 1 ) type1 ( arr , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; else if ( query [ i ] [ 0 ] == 2 ) type2 ( arr , query , query [ i ] [ 1 ] , query [ i ] [ 2 ] ) ; for ( let i = 1 ; i <= n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function record_sum ( record , l , r , n , adder ) { for ( let i = l ; i <= r ; i ++ ) { record [ i ] += adder ; } } let n = 5 , m = 5 ; let arr = new Array ( n ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = 0 ; } let query = [ [ 1 , 1 , 2 ] , [ 1 , 4 , 5 ] , [ 2 , 1 , 2 ] , [ 2 , 1 , 3 ] , [ 2 , 3 , 4 ] ] ; let record = new Array ( m ) ; for ( let i = 0 ; i < record . length ; i ++ ) { record [ i ] = 0 ; } for ( let i = m - 1 ; i >= 0 ; i -- ) { if ( query [ i ] [ 0 ] == 2 ) { record_sum ( record , query [ i ] [ 1 ] - 1 , query [ i ] [ 2 ] - 1 , m , record [ i ] + 1 ) ; } else { record_sum ( record , i , i , m , 1 ) ; } } for ( let i = 0 ; i < m ; i ++ ) { if ( query [ i ] [ 0 ] == 1 ) { record_sum ( arr , query [ i ] [ 1 ] - 1 , query [ i ] [ 2 ] - 1 , n , record [ i ] ) ; } } for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findCountOfPairs ( a , b , n ) { let ans = 0 ; for ( let i = 1 ; i <= a ; i ++ ) { ans += parseInt ( b / n , 10 ) ; ans += ( i % n + b % n ) >= n ? 1 : 0 ; } return ans ; } let a = 5 , b = 13 , n = 3 ; document . write ( findCountOfPairs ( a , b , n ) ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findCountOfPairs ( a , b , n ) { if ( a > b ) { let temp1 = a ; a = b ; b = temp1 ; } let temp = 1 , count = 0 ; for ( let i = n ; temp > 0 ; i += n ) { if ( a >= i ) { temp = i - 1 ; } else if ( b >= i ) { temp = a ; } else if ( i > b ) { temp = a - ( i - b ) + 1 ; } if ( temp > 0 ) { count += temp ; } } return count ; } let a = 5 , b = 13 , n = 3 ; document . write ( findCountOfPairs ( a , b , n ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
function solveQuery ( start , end , arr ) { let mp = new Map ( ) ; for ( let i = start ; i <= end ; i ++ ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ; let count = 0 ; for ( let [ key , value ] of mp . entries ( ) ) if ( key == value ) count ++ ; return count ; } let A = [ 1 , 2 , 2 , 3 , 3 , 3 ] ; let n = A . length ; let queries = [ [ 0 , 1 ] , [ 1 , 1 ] , [ 0 , 2 ] , [ 1 , 3 ] , [ 3 , 5 ] , [ 0 , 5 ] ] ; let q = queries . length ; for ( let i = 0 ; i < q ; i ++ ) { let start = queries [ i ] [ 0 ] ; let end = queries [ i ] [ 1 ] ; document . write ( " " + ( i + 1 ) + " " + solveQuery ( start , end , A ) + " " ) ; }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function minItems ( k , r ) { for ( let i = 1 ; i < 10 ; i ++ ) if ( ( i * k - r ) % 10 == 0 || ( i * k ) % 10 == 0 ) return i ; return 10 ; } let k = 15 ; let r = 2 ; document . write ( minItems ( k , r ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function answer_query ( a , n , l , r ) { var count = 0 ; for ( var i = l ; i < r ; i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ; return count ; } var a = [ 1 , 2 , 2 , 2 , 3 , 3 , 4 , 4 , 4 ] var n = a . length ; var L , R ; L = 1 ; R = 8 ; document . write ( answer_query ( a , n , L , R ) + " " ) ; L = 0 ; R = 4 ; document . write ( answer_query ( a , n , L , R ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = null ; this . right = null ; } } let grid = new Map ( ) ; function addConsideringGrid ( root , level , index ) { if ( root == null ) return ; if ( grid . has ( level - index ) ) { grid . set ( level - index , grid . get ( level - index ) + ( root . data ) ) ; } else { grid . set ( level - index , root . data ) ; } addConsideringGrid ( root . left , level + 1 , index - 1 ) ; addConsideringGrid ( root . right , level + 1 , index + 1 ) ; } function diagonalSum ( root ) { addConsideringGrid ( root , 0 , 0 ) ; let ans = [ ] ; for ( let [ key , value ] of grid ) { ans . push ( value ) ; } return ans ; } let root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 9 ) ; root . left . right = new Node ( 6 ) ; root . right . left = new Node ( 4 ) ; root . right . right = new Node ( 5 ) ; root . right . left . right = new Node ( 7 ) ; root . right . left . left = new Node ( 12 ) ; root . left . right . left = new Node ( 11 ) ; root . left . left . right = new Node ( 10 ) ; let v = diagonalSum ( root ) ; for ( let i = 0 ; i < v . length ; i ++ ) document . write ( v [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
const N = 1000 ; let prefixans = new Uint8Array ( N ) ; function countIndex ( a , n ) { for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == a [ i + 1 ] ) prefixans [ i ] = 1 ; if ( i != 0 ) prefixans [ i ] += prefixans [ i - 1 ] ; } } function answer_query ( l , r ) { if ( l == 0 ) return prefixans [ r - 1 ] ; else return prefixans [ r - 1 ] - prefixans [ l - 1 ] ; } let a = [ 1 , 2 , 2 , 2 , 3 , 3 , 4 , 4 , 4 ] ; let n = a . length ; countIndex ( a , n ) ; let L , R ; L = 1 ; R = 8 ; document . write ( answer_query ( L , R ) + " " ) ; L = 0 ; R = 4 ; document . write ( answer_query ( L , R ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function primeSubarrays ( A , n ) { var max_val = parseInt ( Math . pow ( 10 , 7 ) ) ; var prime = new Array ( max_val + 1 ) ; prime . fill ( true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( var p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( var i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } var cnt = 0 ; for ( var i = 0 ; i < n - 1 ; ++ i ) { var val = A [ i ] ; for ( var j = i + 1 ; j < n ; ++ j ) { val += A [ j ] ; if ( prime [ val ] ) ++ cnt ; } } return cnt ; } var A = [ 1 , 2 , 3 , 4 , 5 ] ; var n = A . length ; document . write ( primeSubarrays ( A , n ) ) ;

Index/key variables: i, j, p, val
Accumulator variables: i, p, val
Iterator variables: i, j, p
Javascript program:
function countMinSwaps ( st ) { let min_swaps = 0 ; let odd_0 = 0 , even_0 = 0 ; let odd_1 = 0 , even_1 = 0 ; let n = st . length ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { if ( st [ i ] == ' ' ) { even_1 ++ ; } else { even_0 ++ ; } } else { if ( st [ i ] == ' ' ) { odd_1 ++ ; } else { odd_0 ++ ; } } } let cnt_swaps_1 = Math . min ( even_0 , odd_1 ) ; let cnt_swaps_2 = Math . min ( even_1 , odd_0 ) ; return Math . min ( cnt_swaps_1 , cnt_swaps_2 ) ; } let st = " " ; document . write ( countMinSwaps ( st ) ) ;

Index/key variables: i
Accumulator variables: even_0, even_1, i, odd_0, odd_1
Iterator variables: i
Javascript program:
function initializeDiffArray ( A ) { let n = A . length ; let D = [ ] ; D [ 0 ] = A [ 0 ] , D [ n ] = 0 ; for ( let i = 1 ; i < n ; i ++ ) D [ i ] = A [ i ] - A [ i - 1 ] ; return D ; } function update ( D , l , r , x ) { D [ l ] += x ; D [ r + 1 ] -= x ; return D ; } function printArray ( A , D ) { for ( let i = 0 ; i < A . length ; i ++ ) { if ( i == 0 ) A [ i ] = D [ i ] ; else A [ i ] = D [ i ] + A [ i - 1 ] ; document . write ( A [ i ] + " " ) ; } document . write ( " " ) ; } let A = [ 10 , 5 , 20 , 40 ] ; let D = initializeDiffArray ( A ) ; D = update ( D , 0 , 1 , 10 ) ; printArray ( A , D ) ; D = update ( D , 1 , 3 , 20 ) ; D = update ( D , 2 , 2 , 30 ) ; printArray ( A , D ) ;

Index/key variables: i, l, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSubArraySum ( a , size ) { var maxint = Math . pow ( 2 , 53 ) var max_so_far = - maxint - 1 var max_ending_here = 0 for ( var i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] if ( max_so_far < max_ending_here ) max_so_far = max_ending_here if ( max_ending_here < 0 ) max_ending_here = 0 } return max_so_far } var a = [ - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 ] document . write ( " " , maxSubArraySum ( a , a . length ) )

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function solve ( arr , n ) { let ans = new Array ( n ) ; for ( var i = 0 ; i < ans . length ; i ++ ) { ans [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { ans [ i ] [ j ] = arr [ j ] [ ( i + j ) % n ] ; } } return ans ; } function show ( arr , n ) { let res = solve ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { document . write ( res [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } function makeArray ( n ) { let arr = new Array ( n ) ; for ( var i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = new Array ( 2 ) ; } let c = 1 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) arr [ i ] [ j ] = c ++ ; } return arr ; } let n = 5 ; let arr = makeArray ( n ) ; show ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: c, i, j
Iterator variables: i, j
Javascript program:
function findMinRooms ( slots , n , m ) { let counts = Array ( m ) . fill ( 0 ) ; for ( let i = 0 ; i < m ; i ++ ) counts [ i ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = 0 ; j < m ; j ++ ) if ( slots [ i ] [ j ] == ' ' ) counts [ j ] ++ ; let max = - 1 ; for ( let i = 0 ; i < m ; i ++ ) if ( max < counts [ i ] ) max = counts [ i ] ; return max ; } let n = 3 , m = 7 ; let slots = [ " " , " " , " " ] ; document . write ( findMinRooms ( slots , n , m ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxSubArraySum ( a , size ) { let max_so_far = a [ 0 ] ; let curr_max = a [ 0 ] ; for ( let i = 1 ; i < size ; i ++ ) { curr_max = Math . max ( a [ i ] , curr_max + a [ i ] ) ; max_so_far = Math . max ( max_so_far , curr_max ) ; } return max_so_far ; } let a = [ - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 ] ; let n = a . length ; document . write ( " " , maxSubArraySum ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countCurrency ( amount ) { let notes = [ 2000 , 500 , 200 , 100 , 50 , 20 , 10 , 5 , 1 ] ; let noteCounter = Array ( 9 ) . fill ( 0 ) ; for ( let i = 0 ; i < 9 ; i ++ ) { if ( amount >= notes [ i ] ) { noteCounter [ i ] = Math . floor ( amount / notes [ i ] ) ; amount = amount - noteCounter [ i ] * notes [ i ] ; } } document . write ( " " + " " ) ; for ( let i = 0 ; i < 9 ; i ++ ) { if ( noteCounter [ i ] != 0 ) { document . write ( notes [ i ] + " " + noteCounter [ i ] + " " ) ; } } } let amount = 868 ; countCurrency ( amount ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function NextFit ( blockSize , m , processSize , n ) { let allocation = Array . from ( { length : n } , ( _ , i ) => - 1 ) , j = 0 ; for ( let i = 0 ; i < n ; i ++ ) { while ( j < m ) { if ( blockSize [ j ] >= processSize [ i ] ) { allocation [ i ] = j ; blockSize [ j ] -= processSize [ i ] ; break ; } j = ( j + 1 ) % m ; } } document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( i + 1 + Array ( 20 ) . fill ( ' \xa0 ' ) . join ( ' ' ) + processSize [ i ] + Array ( 20 ) . fill ( ' \xa0 ' ) . join ( ' ' ) ) ; if ( allocation [ i ] != - 1 ) { document . write ( allocation [ i ] + 1 ) ; } else { document . write ( " " ) ; } document . write ( " " ) ; } } let blockSize = [ 5 , 10 , 20 ] ; let processSize = [ 10 , 20 , 5 ] ; let m = blockSize . length ; let n = processSize . length ; NextFit ( blockSize , m , processSize , n ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
var price = [ 2 , 30 , 15 , 10 , 8 , 25 , 80 ] ; var profit = 0 ; for ( i = 1 ; i < price . length ; i ++ ) { var sub = price [ i ] - price [ i - 1 ] ; if ( sub > 0 ) profit += sub ; } document . write ( " " + profit ) ;

Index/key variables: i
Accumulator variables: i, profit
Iterator variables: i
Javascript program:
function findMinAvgSubarray ( arr , n , k ) { if ( n < k ) return ; let res_index = 0 ; let curr_sum = 0 ; for ( let i = 0 ; i < k ; i ++ ) curr_sum += arr [ i ] ; let min_sum = curr_sum ; for ( let i = k ; i < n ; i ++ ) { curr_sum += arr [ i ] - arr [ i - k ] ; if ( curr_sum < min_sum ) { min_sum = curr_sum ; res_index = ( i - k + 1 ) ; } } document . write ( " " + res_index + " " + ( res_index + k - 1 ) + " " ) ; } let arr = [ 3 , 7 , 90 , 20 , 10 , 50 , 40 ] ; let k = 3 ; let n = arr . length ; findMinAvgSubarray ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: curr_sum, i
Iterator variables: i
Javascript program:
let seg = [ 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] ; function computeSegment ( x ) { if ( x == 0 ) return seg [ 0 ] ; let count = 0 ; while ( x > 0 ) { count += seg [ x % 10 ] ; x = parseInt ( x / 10 , 10 ) ; } return count ; } function elementMinSegment ( arr , n ) { let minseg = computeSegment ( arr [ 0 ] ) ; let minindex = 0 ; for ( let i = 1 ; i < n ; i ++ ) { let temp = computeSegment ( arr [ i ] ) ; if ( temp < minseg ) { minseg = temp ; minindex = i ; } } return arr [ minindex ] ; } let arr = [ 489 , 206 , 745 , 123 , 756 ] ; let n = arr . length ; document . write ( elementMinSegment ( arr , n ) ) ;

Index/key variables: i, minindex
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findLargest ( m , s ) { if ( s == 0 ) { ( m == 1 ) ? document . write ( " " + 0 ) : document . write ( " " ) ; return ; } if ( s > 9 * m ) { document . write ( " " ) ; return ; } let res = new Array ( m ) ; for ( let i = 0 ; i < m ; i ++ ) { if ( s >= 9 ) { res [ i ] = 9 ; s -= 9 ; } else { res [ i ] = s ; s = 0 ; } } document . write ( " " ) ; for ( let i = 0 ; i < m ; i ++ ) document . write ( res [ i ] ) ; } let s = 9 , m = 2 ; findLargest ( m , s ) ;

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Javascript program:
function minJumps ( arr , n ) { if ( n == 1 ) return 0 ; let res = Number . MAX_VALUE ; for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( i + arr [ i ] >= n - 1 ) { let sub_res = minJumps ( arr , i + 1 ) ; if ( sub_res != Number . MAX_VALUE ) res = Math . min ( res , sub_res + 1 ) ; } } return res ; } let arr = [ 1 , 3 , 6 , 3 , 2 , 3 , 6 , 8 , 9 , 5 ] ; let n = arr . length ; document . write ( " " ) ; document . write ( " " + minJumps ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let dp = new Array ( 1001 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = ( new Array ( 3001 ) . fill ( - 1 ) ) } function recBananaCnt ( A , B , C ) { if ( B <= A ) { return 0 ; } if ( B <= C ) { return B - A ; } if ( A == 0 ) { return B ; } if ( dp [ A ] [ B ] != - 1 ) { return dp [ A ] [ B ] ; } let maxCount = Number . MIN_VALUE ; let tripCount = B % C == 0 ? Math . floor ( ( 2 * B ) / C ) - 1 : Math . floor ( ( 2 * B ) / C ) + 1 ; for ( let i = 1 ; i <= A ; i ++ ) { let curCount = recBananaCnt ( A - i , B - tripCount * i , C ) ; if ( curCount > maxCount ) { maxCount = curCount ; dp [ A ] [ B ] = maxCount ; } } return maxCount ; } function maxBananaCnt ( A , B , C ) { return recBananaCnt ( A , B , C ) ; } let A = 1000 ; let B = 3000 ; let C = 1000 ; document . write ( maxBananaCnt ( A , B , C ) ) ;

Index/key variables: A, B, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function calculate ( position , used , unused , P , M , dp ) { if ( position == P ) { return unused == 0 ? 1 : 0 ; } if ( dp [ position ] [ used ] [ unused ] != - 1 ) return dp [ position ] [ used ] [ unused ] ; let result = 0 ; if ( unused > 0 ) { result += calculate ( position + 1 , used + 1 , unused - 1 , P , M , dp ) * unused ; } if ( used > M ) { result += calculate ( position + 1 , used , unused , P , M , dp ) * ( used - M ) ; } return dp [ position ] [ used ] [ unused ] = result ; } function solve ( N , P , M ) { var dp = new Array ( 101 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 101 ) . fill ( - 1 ) ; } for ( let i = 0 ; i < dp . length ; i ++ ) { for ( let j = 0 ; j < dp [ 0 ] . length ; j ++ ) { dp [ i ] [ j ] = new Array ( 101 ) . fill ( - 1 ) ; } } return calculate ( 0 , 0 , N , P , M , dp ) ; } let N = 2 , M = 0 , P = 3 ; document . write ( solve ( N , P , M ) ) ;

Index/key variables: i, j, position, unused, used
Accumulator variables: i, j, result
Iterator variables: i, j
Javascript program:
function minJumps ( arr , n ) { var jumps = Array . from ( { length : n } , ( _ , i ) => 0 ) ; var min ; jumps [ n - 1 ] = 0 ; for ( i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] == 0 ) jumps [ i ] = Number . MAX_VALUE ; else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ; else { min = Number . MAX_VALUE ; for ( j = i + 1 ; j < n && j <= arr [ i ] + i ; j ++ ) { if ( min > jumps [ j ] ) min = jumps [ j ] ; } if ( min != Number . MAX_VALUE ) jumps [ i ] = min + 1 ; else jumps [ i ] = min ; } } return jumps [ 0 ] ; } var arr = [ 1 , 3 , 6 , 1 , 0 , 9 ] ; var size = arr . length ; document . write ( " " + " " + minJumps ( arr , size ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let dp = new Array ( 100 ) . fill ( 0 ) . map ( ( ) => new Array ( 1000 ) . fill ( - 1 ) ) ; let prime = new Array ( 1005 ) . fill ( true ) ; function SieveOfEratosthenes ( n ) { prime [ 0 ] = prime [ 1 ] = false ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } function countOfNumbers ( index , sum , N ) { if ( index == N + 1 ) { if ( prime [ sum ] == true ) { return 1 ; } return 0 ; } let val = dp [ index ] [ sum ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( index == 1 ) { for ( let digit = N == 1 ? 0 : 1 ; digit <= 9 ; ++ digit ) { val += countOfNumbers ( index + 1 , sum + digit , N ) ; } } else { for ( let digit = 0 ; digit <= 9 ; ++ digit ) { val += countOfNumbers ( index + 1 , sum + digit , N ) ; } } return val ; } SieveOfEratosthenes ( 1000 ) ; let N = 6 ; document . write ( countOfNumbers ( 1 , 0 , N ) ) ;

Index/key variables: i, index, p, sum
Accumulator variables: i, p, val
Iterator variables: digit, i, p
Javascript program:
let memo ; function dfs ( V , left , K ) { let q = 0 ; let key = V . join ( " " ) ; key += left . toString ( ) ; if ( memo . has ( key ) ) return memo [ key ] ; else if ( left == 0 ) { for ( let i = 1 ; i < K ; ++ i ) if ( V [ i ] > 0 ) { V [ i ] -- ; q = Math . max ( q , 1 + dfs ( V , K - i , K ) ) ; V [ i ] ++ ; } } else { for ( let i = 1 ; i < K ; ++ i ) { if ( V [ i ] > 0 ) { V [ i ] -- ; let nleft = i <= left ? left - i : K + left - i ; q = Math . max ( q , dfs ( V , nleft , K ) ) ; V [ i ] ++ ; } } } if ( memo . has ( key ) ) memo [ key ] = q ; else memo [ key ] = q ; return q ; } function maxGroups ( K , arr ) { let V = new Array ( K ) ; V . fill ( 0 ) ; for ( let x = 0 ; x < arr . length ; x ++ ) V [ arr [ x ] % K ] ++ ; memo = new Map ( ) ; let ans = V [ 0 ] + dfs ( V , 0 , K ) ; return ans ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let K = 3 ; document . write ( maxGroups ( K , arr ) ) ;

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