dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function swap ( N , M , mat , startx_X , starty_X , startx_Y , starty_Y ) { let row = 0 ; let col = 0 ; for ( let i = startx_X ; ; i ++ ) { col = 0 ; for ( let j = startx_X ; ; j ++ ) { let temp = mat [ i ] [ j ] ; mat [ i ] [ j ] = mat [ startx_Y + row ] [ starty_Y + col ] ; mat [ startx_Y + row ] [ starty_Y + col ] = temp ; col ++ ; if ( col >= M / 2 ) break ; } row ++ ; if ( row >= N / 2 ) break ; } } function swapQuadOfMatrix ( N , M , mat , X , Y ) { if ( X == 1 && Y == 2 ) { swap ( N , M , mat , 0 , 0 , 0 , M / 2 ) ; } else if ( X == 1 && Y == 3 ) { swap ( N , M , mat , 0 , 0 , N / 2 , 0 ) ; } else if ( X == 1 && Y == 4 ) { swap ( N , M , mat , 0 , 0 , N / 2 , M / 2 ) ; } else if ( X == 2 && Y == 3 ) { swap ( N , M , mat , 0 , M / 2 , N / 2 , 0 ) ; } else if ( X == 2 && Y == 4 ) { swap ( N , M , mat , 0 , M / 2 , N / 2 , M / 2 ) ; } else if ( X == 3 && Y == 4 ) { swap ( N , M , mat , N / 2 , 0 , N / 2 , M / 2 ) ; } prletMat ( N , M , mat ) ; } function prletMat ( N , M , mat ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { document . write ( mat [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } let N = 6 , M = 6 ; let mat = [ [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 7 , 8 , 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 , 17 , 18 ] , [ 19 , 20 , 21 , 22 , 23 , 24 ] , [ 25 , 26 , 27 , 28 , 29 , 30 ] , [ 31 , 32 , 33 , 34 , 35 , 36 ] ] ; let X = 1 , Y = 4 ; swapQuadOfMatrix ( N , M , mat , X , Y ) ;

Index/key variables: i, j
Accumulator variables: col, i, j, row
Iterator variables: i, j
Javascript program:
function incrementCount ( arr , N ) { let mini = arr [ 0 ] - arr [ 1 ] ; for ( let i = 2 ; i < N ; i ++ ) { mini = Math . min ( mini , arr [ i - 1 ] - arr [ i ] ) ; } document . write ( mini ) ; } let N = 3 ; let arr = [ 12 , 8 , 4 ] ; incrementCount ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countOperations ( n , k ) { var div = 2 * k + 1 ; if ( n / 2 <= k ) { document . write ( 1 + " " ) ; if ( n > k ) document . write ( k + 1 ) ; else document . write ( n ) ; } else { if ( n % div == 0 ) { var oprn = parseInt ( n / div ) ; document . write ( oprn + " " ) ; var pos = k + 1 ; document . write ( pos + " " ) ; for ( i = 1 ; i <= oprn ; i ++ ) { document . write ( pos + " " ) ; pos += div ; } } else { var oprn = parseInt ( n / div + 1 ) ; document . write ( oprn + " " ) ; var pos = n % div ; if ( n % div > k ) pos -= k ; for ( i = 1 ; i <= oprn ; i ++ ) { document . write ( pos + " " ) ; pos += div ; } } } } var str = " " ; var ch = ' ' ; var n = str . length ; var k = 4 ; countOperations ( n , k ) ;

Accumulator variables: i, pos
Iterator variables: i
Javascript program:
/ *Js program for the above approach  / * function largestSubsequence ( s ) { let maxi = 0 ; let prev1 ; for ( let i = 0 ; i < 10 ; i ++ ) { for ( let j = 0 ; j < 10 ; j ++ ) { if ( i != j ) { let len = 0 ; prev1 = String ( j ) ; for ( let k = 0 ; k < s . length ; k ++ ) { if ( s [ k ] == String ( i ) && prev1 == String ( j ) ) { prev1 = s [ k ] ; len ++ ; } else if ( s [ k ] == String ( j ) && prev1 == String ( i ) ) { prev1 = s [ k ] ; len ++ ; } } maxi = Math . max ( len , maxi ) ; } } } if ( maxi != 1 ) document . write ( maxi , ' ' ) ; else document . write ( 0 , ' ' ) ; } let s = " " ; largestSubsequence ( s ) ;

Index/key variables: k
Accumulator variables: i, j, k, len
Iterator variables: i, j, k
Javascript program:
let maxm = 0 ; class Node { constructor ( x ) { this . val = x ; this . left = null ; this . right = null ; } } var root ; function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function find_gcd ( arr ) { if ( arr . length == 1 ) return arr [ 0 ] ; let g = arr [ 0 ] ; for ( let i = 1 ; i < arr . length ; i ++ ) { g = gcd ( g , arr [ 1 ] ) ; } return g ; } function maxm_gcd ( root , ans ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { ans . push ( root . val ) ; maxm = Math . max ( find_gcd ( ans ) , maxm ) ; return ; } ans . push ( root . val ) ; maxm_gcd ( root . left , ans ) ; maxm_gcd ( root . right , ans ) ; } root = new Node ( 15 ) ; root . left = new Node ( 3 ) ; root . right = new Node ( 7 ) ; root . left . left = new Node ( 15 ) ; root . left . right = new Node ( 1 ) ; root . right . left = new Node ( 31 ) ; root . right . right = new Node ( 9 ) ; let arr = [ ] ; maxm_gcd ( root , arr ) ; document . write ( maxm ) ;

Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
function numberOfPairs ( n ) { let count = 0 ; let i = 1 , j = n - 1 ; while ( i < j ) { if ( i + j == n ) { count ++ ; } i ++ ; j -- ; } return count ; } let n = 8 ; document . write ( numberOfPairs ( n ) ) ;

Accumulator variables: count, i, j
Javascript program:
let N = 1e5 + 5 ; let v = new Array ( N ) ; let g = new Array ( N ) ; let vis = new Array ( N ) ; let In = new Array ( N ) ; let low = new Array ( N ) ; let parent = new Array ( N ) ; let rnk = new Array ( N ) ; let bridges = [ ] ; let n , m ; let timer = 0 ; let diameter ; function swap ( x , y ) { let temp = x ; x = y ; y = temp ; } function find_set ( a ) { if ( parent [ a ] == a ) return a ; return parent [ a ] = find_set ( parent [ a ] ) ; } function union_set ( a , b ) { let x = find_set ( a ) , y = find_set ( b ) ; if ( x == y ) return ; if ( rnk [ x ] == rnk [ y ] ) rnk [ x ] ++ ; if ( rnk [ y ] > rnk [ x ] ) swap ( x , y ) ; parent [ y ] = x ; } function dfsBridges ( a , par ) { vis [ a ] = true ; In [ a ] = low [ a ] = timer ++ ; for ( let i = 0 ; i < v [ a ] . length ; i ++ ) { if ( v [ a ] [ i ] == par ) continue ; if ( vis [ v [ a ] [ i ] ] ) low [ a ] = Math . min ( low [ a ] , In [ v [ a ] [ i ] ] ) ; else { dfsBridges ( v [ a ] [ i ] , a ) ; low [ a ] = Math . min ( low [ a ] , low [ v [ a ] [ i ] ] ) ; if ( In [ a ] < low [ v [ a ] [ i ] ] ) bridges . push ( [ v [ a ] [ i ] , a ] ) ; else union_set ( v [ a ] [ i ] , a ) ; } } } function dfsDiameter ( a , par ) { let x = 0 , y = 0 ; for ( let i = 0 ; i < g [ a ] . length ; i ++ ) { if ( g [ a ] [ i ] == par ) continue ; let mx = dfsDiameter ( g [ a ] [ i ] , a ) ; if ( mx > x ) { y = x ; x = mx ; } else if ( mx > y ) y = mx ; } diameter = Math . max ( diameter , x + y ) ; return x + 1 ; } function findMaxBridges ( ) { for ( let i = 0 ; i <= n ; i ++ ) { parent [ i ] = i ; rnk [ i ] = 1 ; } dfsBridges ( 1 , 0 ) ; if ( bridges . length == 0 ) return 0 ; let head = - 1 ; for ( let i = 0 ; i < bridges . length ; i ++ ) { let a = find_set ( bridges [ i ] [ 0 ] ) ; let b = find_set ( bridges [ i ] [ 1 ] ) ; g [ a ] . push ( b ) ; g [ b ] . push ( a ) ; head = a ; } diameter = 0 ; dfsDiameter ( head , 0 ) ; return diameter ; } n = 6 ; m = 6 ; for ( let i = 0 ; i < v . length ; i ++ ) v [ i ] = [ ] ; for ( let i = 0 ; i < g . length ; i ++ ) g [ i ] = [ ] ; v [ 1 ] . push ( 2 ) ; v [ 2 ] . push ( 1 ) ; v [ 2 ] . push ( 3 ) ; v [ 3 ] . push ( 2 ) ; v [ 2 ] . push ( 5 ) ; v [ 5 ] . push ( 2 ) ; v [ 5 ] . push ( 6 ) ; v [ 6 ] . push ( 5 ) ; v [ 6 ] . push ( 3 ) ; v [ 3 ] . push ( 6 ) ; v [ 3 ] . push ( 4 ) ; v [ 4 ] . push ( 4 ) ; let ans = findMaxBridges ( ) ; document . write ( ans + " " ) ;

Index/key variables: a, b, i, x, y
Accumulator variables: i, timer
Iterator variables: i
Javascript program:
function palindromeWinner ( S ) { let freq = new Array ( 26 ) ; for ( let i = 0 ; i < 26 ; i ++ ) { freq [ i ] = 0 ; } let count = 0 ; for ( let i = 0 ; i < S . length ; ++ i ) { if ( freq [ S [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] == 0 ) count ++ ; freq [ S [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let unique = 0 ; let duplicate = 0 ; for ( let i = 0 ; i < 26 ; ++ i ) { if ( freq [ i ] == 1 ) unique ++ ; else if ( freq [ i ] >= 2 ) duplicate ++ ; } if ( unique == 1 && ( unique + duplicate ) == count ) return 1 ; return 2 ; } let S = " " ; document . write ( " " + palindromeWinner ( S ) ) ;

Index/key variables: i
Accumulator variables: count, duplicate, i, unique
Iterator variables: i
Javascript program:
function countOfSubstrings ( s ) { var n = s . length ; var x = parseInt ( Math . sqrt ( n ) ) ; var ones = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) ones . push ( i ) ; } if ( ones . length == 0 ) return 0 ; ones . push ( n ) ; var totCount = Array ( n * x + n ) . fill ( 0 ) ; var sum = 0 ; for ( var k = 0 ; k <= x ; k ++ ) { var now = 0 ; totCount [ k * n ] ++ ; for ( var j = 1 ; j <= n ; j ++ ) { if ( s [ j - 1 ] == ' ' ) now ++ ; var index = j - k * now ; sum += totCount [ index + k * n ] ; totCount [ index + k * n ] ++ ; } now = 0 ; totCount [ k * n ] -- ; for ( var j = 1 ; j <= n ; j ++ ) { if ( s [ j - 1 ] == ' ' ) now ++ ; var index = j - k * now ; totCount [ index + k * n ] -- ; } } var prefix_sum = Array ( n ) . fill ( - 1 ) ; var cnt = 0 ; for ( var i = 0 ; i < n ; i ++ ) { prefix_sum [ i ] = cnt ; if ( s [ i ] == ' ' ) cnt ++ ; } for ( var k = 0 ; k < n ; k ++ ) { for ( var j = 1 ; j <= parseInt ( n / x ) && prefix_sum [ k ] + j <= cnt ; j ++ ) { var l = ones [ prefix_sum [ k ] + j - 1 ] - k + 1 ; var r = ones [ prefix_sum [ k ] + j ] - k ; l = Math . max ( l , j * ( x + 1 ) ) ; if ( l <= r ) { sum += parseInt ( r / j ) - parseInt ( ( l - 1 ) / j ) ; } } } return sum ; } var S = " " ; document . write ( countOfSubstrings ( S ) ) ;

Index/key variables: i, k
Accumulator variables: cnt, i, j, k, now, sum
Iterator variables: i, j, k
Javascript program:
function countSetBits ( n ) { let count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } function largestNum ( n ) { let num = 0 ; let max_setBits = 0 ; for ( let i = 0 ; i <= n ; i ++ ) { let setBits = countSetBits ( i ) ; if ( setBits >= max_setBits ) { num = i ; max_setBits = setBits ; } } return num ; } let N = 345 ; document . write ( largestNum ( N ) ) ;

Accumulator variables: count, i
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = this . right = null ; } } function getLeafCount ( node ) { if ( node == null ) { return 0 ; } let q = [ ] ; let count = 0 ; q . push ( node ) ; while ( q . length != 0 ) { let temp = q . shift ( ) ; if ( temp . left != null ) { q . push ( temp . left ) ; } if ( temp . right != null ) { q . push ( temp . right ) ; } if ( temp . left == null && temp . right == null ) { count ++ ; } } return count ; } 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 ( getLeafCount ( root ) ) ;

Accumulator variables: count
Class/struct names: Node
Javascript program:
function solve ( arr , N , K ) { let count_Arr = new Array ( N + 1 ) . fill ( 0 ) ; let factor = 1 ; let size = N ; while ( size ) { let start = 1 ; let end = size ; count_Arr [ 1 ] += factor * N ; count_Arr [ end + 1 ] -= factor * N ; factor ++ ; size = Math . floor ( size / 2 ) ; } for ( let i = 2 ; i <= N ; i ++ ) count_Arr [ i ] += count_Arr [ i - 1 ] ; let element = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { element . push ( [ arr [ i ] , count_Arr [ i + 1 ] ] ) ; } element . sort ( ( a , b ) => a - b ) ; let start = 1 ; for ( let i = 0 ; i < N ; i ++ ) { let end = start + element [ i ] [ 1 ] - 1 ; if ( K >= start && K <= end ) { return element [ i ] [ 0 ] ; } start += element [ i ] [ 1 ] ; } return - 1 ; } let arr = [ 2 , 4 , 5 , 1 ] ; let N = arr . length ; let K = 13 ; document . write ( solve ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: factor, i, start
Iterator variables: i
Javascript program:
function string ( c , d ) { let s = " " ; for ( let i = 0 ; i < c ; i ++ ) s += d ; return s ; } function next_balanced_sequence ( s ) { let next = " " ; let length = s . length ; let depth = 0 ; for ( let i = length - 1 ; i >= 0 ; -- i ) { if ( s [ i ] == ' ' ) depth -- ; else depth ++ ; if ( s [ i ] == ' ' && depth > 0 ) { depth -- ; let open = ( length - i - 1 - depth ) / 2 ; let close = length - i - 1 - open ; next = s . substr ( 0 , i ) + ' ' + string ( open , ' ' ) + string ( close , ' ' ) ; break ; } } return next ; } let s = " " ; document . write ( next_balanced_sequence ( s ) ) ;

Index/key variables: i
Accumulator variables: depth, i, s
Iterator variables: i
Javascript program:
function printMaxNumber ( n ) { if ( n & 1 ) { document . write ( " " ) ; for ( var i = 0 ; i < ( n - 3 ) / 2 ; i ++ ) document . write ( " " ) ; } else { for ( var i = 0 ; i < n / 2 ; i ++ ) document . write ( " " ) ; } } var n = 5 ; printMaxNumber ( n ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function getSum ( n ) { let sumOdd = 0 ; let sumEven = 0 ; let num = ( n ) . toString ( ) ; for ( let i = 0 ; i < num . length ; i ++ ) if ( i % 2 == 0 ) sumOdd = sumOdd + ( num [ i ] - ' ' ) ; else sumEven = sumEven + ( num [ i ] - ' ' ) ; document . write ( " " + sumOdd + " " ) ; document . write ( " " + sumEven + " " ) ; } let n = 457892 ; getSum ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . next = this . right = null ; } } function countLeaves ( node ) { if ( node == null ) return 0 ; if ( node . left == null && node . right == null ) return 1 ; return countLeaves ( node . left ) + countLeaves ( node . 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 ( countLeaves ( root ) ) ;

Class/struct names: Node
Javascript program:
function sorted_partitions ( arr ) { let n = arr . length ; let right_min = new Array ( n + 1 ) ; right_min . fill ( 0 ) ; right_min [ n ] = Number . MAX_VALUE ; for ( let i = n - 1 ; i >= 0 ; i -- ) { right_min [ i ] = Math . min ( right_min [ i + 1 ] , arr [ i ] ) ; } let partitions = 0 ; for ( let current_max = arr [ 0 ] , i = 0 ; i < n ; i ++ ) { current_max = Math . max ( current_max , arr [ i ] ) ; if ( current_max <= right_min [ i + 1 ] ) partitions ++ ; } return partitions ; } let arr = [ 3 , 1 , 2 , 4 , 100 , 7 , 9 ] ; let ans = sorted_partitions ( arr ) ; document . write ( ans ) ;

Index/key variables: i, n
Accumulator variables: i, partitions
Iterator variables: current_max, i
Javascript program:
function getMinCost ( arr , n ) { let min_ele = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { min_ele = Math . min ( min_ele , arr [ i ] ) ; } return min_ele * ( n - 1 ) ; } let arr = [ 4 , 2 , 5 ] ; let n = arr . length ; document . write ( getMinCost ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countMinSwaps ( s ) { var N = s . length ; var one = 0 ; var zero = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ' ) one ++ ; else zero ++ ; } if ( one > zero + 1 zero > one + 1 ) return - 1 ; if ( N % 2 == 1 ) { var num = ( N + 1 ) / 2 ; var one_even = 0 , zero_even = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { if ( s . charAt ( i ) == ' ' ) one_even ++ ; else zero_even ++ ; } } if ( one > zero ) return num - one_even ; else return num - zero_even ; } else { var one_odd = 0 , one_even = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ' ) { if ( i % 2 == 1 ) one_odd ++ ; else one_even ++ ; } } return Math . min ( N / 2 - one_odd , N / 2 - one_even ) ; } } var s = " " ; document . write ( countMinSwaps ( s ) ) ;

Accumulator variables: i, one, one_even, one_odd, zero, zero_even
Iterator variables: i
Javascript program:
let st = " " ; let len = st . length ; for ( let i = 0 ; i < len ; i ++ ) { if ( st [ i ] == ' ' ) n += 1 ; if ( st [ i ] == ' ' ) s += 1 ; if ( st [ i ] == ' ' ) w += 1 ; if ( st [ i ] == ' ' ) e += 1 ; } if ( n == s && w == e ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: e, i, n, s, w
Iterator variables: i
Javascript program:
function cost ( a , n ) { let min = a [ 0 ] ; for ( let i = 1 ; i < a . length ; i ++ ) { if ( a [ i ] < min ) min = a [ i ] ; } return ( n - 1 ) * min ; } let a = [ 4 , 3 , 2 ] ; let n = a . length ; document . write ( cost ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minCost ( coin , n , k ) { coin . sort ( function ( a , b ) { return a - b } ) var coins_needed = Math . ceil ( n / ( k + 1 ) ) ; var ans = 0 ; for ( var i = 0 ; i <= coins_needed - 1 ; i ++ ) ans += coin [ i ] ; return ans ; } var coin = [ 8 , 5 , 3 , 10 , 2 , 1 , 15 , 25 ] var n = coin . length ; var k = 3 ; document . write ( minCost ( coin , n , k ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
let deno = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 , 500 , 1000 ] ; let n = deno . length ; function findMin ( V ) { let ans = [ ] ; for ( let i = n - 1 ; i >= 0 ; i -- ) { while ( V >= deno [ i ] ) { V -= deno [ i ] ; ans . push ( deno [ i ] ) ; } } for ( let i = 0 ; i < ans . length ; i ++ ) { document . write ( " " + ans [ i ] ) ; } } n = 93 ; document . write ( " " + " " + n + " " ) ; findMin ( n ) ;

Index/key variables: i
Accumulator variables: V, i
Iterator variables: i
Javascript program:
function MinimumRemovals ( a , N , K ) { let b = new Array ( N + 1 ) ; for ( let i = 0 ; i < N ; i ++ ) { b [ i + 1 ] = a [ i ] ; } let dp = new Array ( N + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( N + 1 ) . fill ( 0 ) ) ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j <= i ; j ++ ) { dp [ i + 1 ] [ j ] = Math . max ( dp [ i + 1 ] [ j ] , dp [ i ] [ j ] ) ; dp [ i + 1 ] [ j + 1 ] = Math . max ( dp [ i + 1 ] [ j + 1 ] , dp [ i ] [ j ] + ( ( b [ i + 1 ] == j + 1 ) ? 1 : 0 ) ) ; } } for ( let j = N ; j >= 0 ; j -- ) { if ( dp [ N ] [ j ] >= K ) { return ( N - j ) ; } } return - 1 ; } let arr = [ 5 , 1 , 3 , 2 , 3 ] ; let K = 2 ; let N = arr . length document . write ( MinimumRemovals ( arr , N , K ) ) ;

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countArray ( arr , N , M ) { let dp = new Array ( N ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( M + 2 ) . fill ( 0 ) ; } if ( arr [ 0 ] == - 1 ) { for ( let j = 1 ; j <= M ; j ++ ) { dp [ 0 ] [ j ] = 1 ; } } else { dp [ 0 ] [ arr [ 0 ] ] = 1 ; } for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] != - 1 ) { let j = arr [ i ] ; dp [ i ] [ j ] += dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j + 1 ] ; } if ( arr [ i ] == - 1 ) { for ( let j = 1 ; j <= M ; j ++ ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j + 1 ] ; } } } let arrCount = 0 ; for ( let j = 1 ; j <= M ; j ++ ) { arrCount += dp [ N - 1 ] [ j ] ; } return arrCount ; } let arr = [ 4 , - 1 , 2 , 1 , - 1 , - 1 ] ; let N = arr . length ; let M = 10 ; document . write ( countArray ( arr , N , M ) ) ;

Index/key variables: i, j
Accumulator variables: arrCount, i, j
Iterator variables: i, j
Javascript program:
let dp = Array ( 101 ) . fill ( ) . map ( ( ) => Array ( 101 ) ) ; function maxMergingScore ( A , N ) { for ( let len = 1 ; len < N ; ++ len ) { for ( let i = 0 ; i + len < N ; ++ i ) { let j = i + len ; dp [ i ] [ j ] = 0 ; for ( let k = i + 1 ; k < j ; ++ k ) { dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k ] [ j ] + A [ i ] * A [ j ] ) ; } } } return dp [ 0 ] [ N - 1 ] ; } let N = 4 ; let A = [ 1 , 2 , 3 , 4 ] ; document . write ( maxMergingScore ( A , N ) + " " ) ; N = 2 ; let B = [ 1 , 55 ] ; document . write ( maxMergingScore ( B , N ) + " " ) ;

Index/key variables: i, j, k
Iterator variables: i, k, len
Javascript program:
function LongestOddEvenSubarray ( A , N ) { let dp ; dp = 1 ; let ans = 1 ; for ( let i = 1 ; i < N ; i ++ ) { if ( ( A [ i ] % 2 == 0 && A [ i - 1 ] % 2 == 0 ) || ( A [ i ] % 2 != 0 && A [ i - 1 ] % 2 != 0 ) ) { dp = dp + 1 ; ans = Math . max ( ans , dp ) ; } else dp = 1 ; } return ans ; } let A = [ 2 , 5 , 7 , 2 , 4 , 6 , 8 , 3 ] ; let N = A . length ; document . write ( LongestOddEvenSubarray ( A , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var dp = Array ( 100 ) . fill ( ) . map ( ( ) => Array ( 10 ) . fill ( ) . map ( ( ) => Array ( 10 ) . fill ( - 1 ) ) ) ; function countOfNumbers ( digit , prev1 , prev2 , n ) { if ( digit == n + 1 ) { return 1 ; } var val = dp [ digit ] [ prev1 ] [ prev2 ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( digit == 1 ) { for ( var i = ( n == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } else if ( digit == 2 ) { for ( var i = 0 ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } else { var mean = prev1 ; var current = ( 2 * mean ) - prev2 ; if ( current >= 0 && current <= 9 ) val += countOfNumbers ( digit + 1 , current , prev1 , n ) ; if ( ( current + 1 ) >= 0 && ( current + 1 ) <= 9 ) val += countOfNumbers ( digit + 1 , current + 1 , prev1 , n ) ; } return val ; } var n = 2 ; document . write ( countOfNumbers ( 1 , 0 , 0 , n ) ) ;

Index/key variables: digit, prev1, prev2
Accumulator variables: val
Iterator variables: i
Javascript program:
var dp = Array . from ( Array ( 50 ) , ( ) => Array ( 10 ) ) ; for ( var i = 0 ; i < 10 ; i ++ ) for ( var j = 0 ; j < 10 ; j ++ ) dp [ i ] [ j ] = new Array ( 10 ) . fill ( - 1 ) ; function countOfNumbers ( digit , prev1 , prev2 , N ) { if ( digit == N + 1 ) return 1 ; if ( dp [ digit ] [ prev1 ] [ prev2 ] != - 1 ) return dp [ digit ] [ prev1 ] [ prev2 ] ; dp [ digit ] [ prev1 ] [ prev2 ] = 0 ; if ( digit == 1 ) { for ( var j = ( N == 1 ? 0 : 1 ) ; j <= 9 ; ++ j ) { dp [ digit ] [ prev1 ] [ prev2 ] += countOfNumbers ( digit + 1 , j , prev1 , N ) ; } } else if ( digit == 2 ) { for ( var j = 0 ; j <= 9 ; ++ j ) { dp [ digit ] [ prev1 ] [ prev2 ] += countOfNumbers ( digit + 1 , j , prev1 , N ) ; } } else { for ( var j = 0 ; j <= Math . abs ( prev1 - prev2 ) ; ++ j ) { dp [ digit ] [ prev1 ] [ prev2 ] += countOfNumbers ( digit + 1 , j , prev1 , N ) ; } } return dp [ digit ] [ prev1 ] [ prev2 ] ; } var N = 3 ; document . write ( countOfNumbers ( 1 , 0 , 0 , N ) ) ;

Index/key variables: digit, i, j, prev1, prev2
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function count0 ( s ) { let count = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) { count ++ ; } } return count ; } function solve ( vec , A , B , idx , dp ) { if ( idx == vec . length A + B == 0 ) { return 0 ; } if ( dp [ A ] [ B ] [ idx ] > 0 ) { return dp [ A ] [ B ] [ idx ] ; } let zero = count0 ( vec [ idx ] ) ; let one = vec [ idx ] . length - zero ; let inc = 0 ; if ( zero <= A && one <= B ) { inc = 1 + solve ( vec , A - zero , B - one , idx + 1 , dp ) ; } let exc = solve ( vec , A , B , idx + 1 , dp ) ; dp [ A ] [ B ] [ idx ] = Math . max ( inc , exc ) ; return dp [ A ] [ B ] [ idx ] ; } function MaxSubsetlength ( arr , A , B ) { let dp = new Array ( A + 1 ) ; for ( let i = 0 ; i < A + 1 ; i ++ ) { dp [ i ] = new Array ( B + 1 ) ; for ( let j = 0 ; j < B + 1 ; j ++ ) { dp [ i ] [ j ] = new Array ( arr . length + 1 ) ; for ( let k = 0 ; k < arr . length + 1 ; k ++ ) { dp [ i ] [ j ] [ k ] = 0 ; } } } return solve ( arr , A , B , 0 , dp ) ; } let arr = [ " " , " " , " " ] ; let A = 1 , B = 1 ; document . write ( MaxSubsetlength ( arr , A , B ) ) ;

Index/key variables: A, B, i, idx, j, k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k