dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function solve ( n , k , mod , dp ) { if ( n < 0 ) return 0 ; if ( n == 0 ) return 1 ; if ( dp [ n ] != - 1 ) return dp [ n ] ; let cnt = 0 ; for ( let i = 2 ; i <= k ; i += 2 ) { cnt = ( cnt % mod + solve ( n - i , k , mod , dp ) % mod ) % mod ; } dp [ n ] = cnt ; return cnt ; } let mod = ( 1e9 + 7 ) ; let n = 4 , k = 2 ; let dp = new Array ( n + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) dp [ i ] = - 1 ; let ans = solve ( n , k , mod , dp ) ; document . write ( ans ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
var f = Array ( 12 ) . fill ( 0 ) ; function fact ( ) { f [ 0 ] = f [ 1 ] = 1 ; for ( var i = 2 ; i <= 10 ; i ++ ) f [ i ] = i * 1 * f [ i - 1 ] ; } function solve ( arr , n , k ) { fact ( ) ; var even = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; } if ( k > even ) document . write ( 0 ) ; else { document . write ( f [ even ] / ( f [ k ] * f [ even - k ] ) ) ; } } var arr = [ 1 , 2 , 3 , 4 ] ; var n = arr . length ; var k = 1 ; solve ( arr , n , k ) ;

Index/key variables: even, i, k
Accumulator variables: even, i
Iterator variables: i
Javascript program:
var MOD = 1000000007 ; function nCrModp ( n , r ) { if ( n % 2 == 1 ) { return - 1 ; } var C = Array ( r + 1 ) . fill ( 0 ) ; C [ 0 ] = 1 ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = Math . min ( i , r ) ; j > 0 ; j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % MOD ; } return C [ r ] ; } var N = 6 ; document . write ( nCrModp ( N , N / 2 ) ) ;

Index/key variables: j, r
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printMinOperations ( N ) { var dp = Array ( N + 1 ) for ( var i = 0 ; i < N + 1 ; i ++ ) dp [ i ] = N ; dp [ 1 ] = 0 ; for ( var i = 2 ; i < N + 1 ; i ++ ) { if ( i % 2 == 0 && dp [ i ] > dp [ i / 2 ] + 1 ) dp [ i ] = dp [ i / 2 ] + 1 ; if ( i % 3 == 0 && dp [ i ] > dp [ i / 3 ] + 1 ) dp [ i ] = dp [ i / 3 ] + 1 ; if ( dp [ i ] > dp [ i - 1 ] + 1 ) dp [ i ] = dp [ i - 1 ] + 1 ; } document . write ( dp [ N ] + " " ) ; var seq = [ ] ; while ( N > 1 ) { seq . push ( N ) ; if ( dp [ N - 1 ] == dp [ N ] - 1 ) N = N - 1 ; else if ( N % 2 == 0 && dp [ N / 2 ] == dp [ N ] - 1 ) N = N / 2 ; else N = N / 3 ; } seq . push ( 1 ) ; for ( var i = seq . length - 1 ; i >= 0 ; i -- ) document . write ( seq [ i ] + " " ) ; document . write ( " " ) ; } var X = 96234 ; printMinOperations ( X ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxLength ( arr , n ) { let dp = [ ] ; for ( let i = 1 ; i < n ; i ++ ) { dp [ i ] = 1 ; } for ( let i = n - 1 ; i > 1 ; i -- ) { for ( let j = 1 ; j <= Math . sqrt ( i ) ; j ++ ) { if ( i % j == 0 ) { let s = i / j ; if ( s == j ) { if ( arr [ i ] > arr [ s ] ) { dp [ s ] = Math . max ( dp [ i ] + 1 , dp [ s ] ) ; } } else { if ( s != i && arr [ i ] > arr [ s ] ) dp [ s ] = Math . max ( dp [ i ] + 1 , dp [ s ] ) ; if ( arr [ i ] > arr [ j ] ) { dp [ j ] = Math . max ( dp [ i ] + 1 , dp [ j ] ) ; } } } } } let max = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( dp [ i ] > max ) max = dp [ i ] ; } document . write ( max ) ; } let arr = [ 0 , 1 , 4 , 2 , 3 , 6 , 4 , 9 ] ; let size = arr . length ; maxLength ( arr , size ) ;

Index/key variables: i, j, s
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxProfit ( price , n ) { var buy1 , profit1 , buy2 , profit2 ; buy1 = buy2 = Number . MAX_VALUE ; profit1 = profit2 = 0 ; for ( i = 0 ; i < n ; i ++ ) { buy1 = Math . min ( buy1 , price [ i ] ) ; profit1 = Math . max ( profit1 , price [ i ] - buy1 ) ; buy2 = Math . min ( buy2 , price [ i ] - profit1 ) ; profit2 = Math . max ( profit2 , price [ i ] - buy2 ) ; } return profit2 ; } var price = [ 2 , 30 , 15 , 10 , 8 , 25 , 80 ] ; var n = price . length ; document . write ( " " + maxProfit ( price , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findMaximumScore ( a , n ) { let freq = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( freq . has ( a [ i ] ) ) { freq . set ( a [ i ] , freq . get ( a [ i ] ) + 1 ) ; } else { freq . set ( a [ i ] , 1 ) ; } } let dp = new Array ( Math . max ( ... a ) + 1 ) ; dp [ 0 ] = 0 ; dp [ 1 ] = freq . get ( 1 ) ; for ( let i = 2 ; i < dp . length ; i ++ ) dp [ i ] = Math . max ( dp [ i - 1 ] , dp [ i - 2 ] + freq . get ( i ) * i ) ; return dp [ dp . length - 1 ] ; } let n = 3 ; let a = [ 1 , 2 , 3 ] ; document . write ( findMaximumScore ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maximizeSum ( arr ) { let n = arr . length ; let sum = 0 ; for ( let i = 0 ; i < n ; i = i + 2 ) sum += arr [ i ] ; let leftDP = new Array ( Math . floor ( n / 2 ) ) ; let rightDP = new Array ( Math . floor ( n / 2 ) ) ; for ( let i = 0 ; i < n / 2 ; i ++ ) { leftDP [ i ] = 0 ; rightDP [ i ] = 0 ; } let c = 0 ; for ( let i = 1 ; i < n ; i = i + 2 ) { let leftDiff = arr [ i ] - arr [ i - 1 ] ; if ( c - 1 < 0 ) leftDP [ i ] = leftDiff ; else { if ( leftDP [ i ] > 0 ) leftDP [ i ] = leftDiff + leftDP [ i - 1 ] ; else leftDP [ i ] = leftDiff ; } let rightDiff ; if ( i + 1 >= arr . length ) rightDiff = 0 ; else rightDiff = arr [ i ] - arr [ i + 1 ] ; if ( c - 1 < 0 ) rightDP [ i ] = rightDiff ; else { if ( rightDP [ i ] > 0 ) rightDP [ i ] = rightDiff + rightDP [ i - 1 ] ; else rightDP [ i ] = rightDiff ; } c ++ ; } let max = 0 ; for ( let i = 0 ; i < n / 2 ; i ++ ) { max = Math . max ( max , Math . max ( leftDP [ i ] , rightDP [ i ] ) ) ; } return max + sum ; } let arr = [ 7 , 8 , 4 , 5 , 7 , 6 , 8 , 9 , 7 , 3 ] ; let ans = maximizeSum ( arr ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: c, i, sum
Iterator variables: i
Javascript program:
function validsubsequences ( arr , n ) { let dp = new Array ( n + 1 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < n + 1 ; i ++ ) { dp [ i ] [ 0 ] = 0 ; dp [ i ] [ 1 ] = 0 ; } for ( let i = 1 ; i <= n ; i ++ ) { if ( arr [ i - 1 ] % 2 != 0 ) { dp [ i ] [ 1 ] += 1 ; dp [ i ] [ 1 ] += dp [ i - 1 ] [ 0 ] ; dp [ i ] [ 1 ] += dp [ i - 1 ] [ 1 ] ; dp [ i ] [ 0 ] += dp [ i - 1 ] [ 0 ] ; } else { dp [ i ] [ 0 ] += 1 ; dp [ i ] [ 0 ] += dp [ i - 1 ] [ 1 ] ; dp [ i ] [ 0 ] += dp [ i - 1 ] [ 0 ] ; dp [ i ] [ 1 ] += dp [ i - 1 ] [ 1 ] ; } } return ( dp [ n ] [ 0 ] + dp [ n ] [ 1 ] ) ; } let arr = [ 5 , 6 , 9 , 7 ] ; let n = arr . length ; document . write ( validsubsequences ( arr , n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function getCount ( n , k ) { if ( n == 1 ) return 10 ; var dp = new Array ( n + 1 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) dp [ i ] = Array ( 11 ) . fill ( 0 ) ; for ( i = 1 ; i <= 9 ; i ++ ) dp [ 1 ] [ i ] = 1 ; for ( i = 2 ; i <= n ; i ++ ) { for ( j = 0 ; j <= 9 ; j ++ ) { var l = Math . max ( 0 , j - k ) ; var r = Math . min ( 9 , j + k ) ; dp [ i ] [ l ] += dp [ i - 1 ] [ j ] ; dp [ i ] [ r + 1 ] -= dp [ i - 1 ] [ j ] ; } for ( j = 1 ; j <= 9 ; j ++ ) dp [ i ] [ j ] += dp [ i ] [ j - 1 ] ; } var count = 0 ; for ( i = 0 ; i <= 9 ; i ++ ) count += dp [ n ] [ i ] ; return count ; } var n = 2 , k = 1 ; document . write ( getCount ( n , k ) ) ;

Index/key variables: i, j, l, n
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
var X = 6 ; var Z = 2 ; function existPath ( V , edges , u , v ) { var mat = Array . from ( Array ( V ) , ( ) => Array ( V ) ) ; for ( var i = 0 ; i < X ; i ++ ) mat [ edges [ i ] [ 0 ] ] [ edges [ i ] [ 1 ] ] = true ; for ( var k = 0 ; k < V ; k ++ ) { for ( var i = 0 ; i < V ; i ++ ) { for ( var j = 0 ; j < V ; j ++ ) { mat [ i ] [ j ] = mat [ i ] [ j ] || mat [ i ] [ k ] && mat [ k ] [ j ] ; } } } if ( u >= V v >= V ) { return false ; } if ( mat [ u ] [ v ] ) return true ; return false ; } var V = 4 ; var edges = [ [ 0 , 2 ] , [ 0 , 1 ] , [ 1 , 2 ] , [ 2 , 3 ] , [ 2 , 0 ] , [ 3 , 3 ] ] ; var u = 1 , v = 3 ; if ( existPath ( V , edges , u , v ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, k, u, v
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function calculate_maximum_splits ( arr , N ) { var pre = [ 0 , - 1 , - 1 ] ; var i ; var dp = new Array ( N ) ; for ( i = 0 ; i < N ; i ++ ) dp [ i ] = 0 ; var C = 0 ; for ( i = 1 ; i < N ; i ++ ) { C = C + arr [ i ] ; C = C % 3 ; if ( pre [ C ] == - 1 ) { dp [ i ] = dp [ i - 1 ] ; } else { dp [ i ] = Math . max ( dp [ i - 1 ] , dp [ pre [ C ] ] + 1 ) ; } pre [ C ] = i ; } document . write ( dp [ N - 1 ] ) ; } var arr = [ 2 , 36 , 1 , 9 , 2 , 0 , 1 , 8 , 1 ] ; var N = arr . length ; calculate_maximum_splits ( arr , N ) ;

Index/key variables: C, i
Accumulator variables: i
Iterator variables: i
Javascript program:
let prime = new Uint8Array ( 1000001 ) ; function seiveOfEratosthenes ( ) { for ( let i = 2 ; i < 1000001 ; i ++ ) { prime [ i ] = 1 ; } for ( let i = 2 ; i * i < 1000001 ; i ++ ) { if ( prime [ i ] == 1 ) { for ( let j = i * i ; j < 1000001 ; j += i ) { prime [ j ] = 0 ; } } } } function CountElements ( arr , n , L , R ) { seiveOfEratosthenes ( ) ; countPrime = new Uint8Array ( n + 1 ) ; for ( let i = 1 ; i <= n ; i ++ ) { countPrime [ i ] = countPrime [ i - 1 ] + prime [ arr [ i - 1 ] ] ; } document . write ( ( countPrime [ R ] - countPrime [ L - 1 ] ) + " " ) ; return ; } let arr = [ 2 , 4 , 5 , 8 ] ; let N = arr . length ; let L = 1 , R = 3 ; CountElements ( arr , N , L , R ) ;

Index/key variables: R, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function OddDivisorsCount ( n , q , a , Query ) { var DP = new Array ( n ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { var x = Math . sqrt ( a [ i ] ) ; if ( x * x == a [ i ] ) DP [ i ] = 1 ; } for ( var i = 1 ; i < n ; i ++ ) { DP [ i ] = DP [ i - 1 ] + DP [ i ] ; } var l , r ; for ( var i = 0 ; i < q ; i ++ ) { l = Query [ i ] [ 0 ] ; r = Query [ i ] [ 1 ] ; if ( l == 0 ) { document . write ( DP [ r ] + " " ) ; } else { document . write ( DP [ r ] - DP [ l - 1 ] + " " ) ; } } } var N = 5 ; var Q = 3 ; var arr = [ 2 , 4 , 5 , 6 , 9 ] ; var Query = [ [ 0 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] ] ; OddDivisorsCount ( N , Q , arr , Query ) ;

Index/key variables: i, r
Accumulator variables: i
Iterator variables: i
Javascript program:
let primes = new Array ( 1000000 ) ; const maxn = 1000000 ; function sieve ( ) { primes . fill ( true ) primes [ 0 ] = primes [ 1 ] = 0 ; for ( let i = 2 ; i * i <= maxn ; i ++ ) { if ( primes [ i ] ) { for ( let j = i * i ; j <= maxn ; j += i ) primes [ j ] = false ; } } } function toBinary ( n ) { let r = " " ; while ( n != 0 ) { r = ( n % 2 == 0 ? " " : " " ) + r ; n = Math . floor ( n / 2 ) ; } return ( r == " " ) ? " " : r ; } function PrimeSplit ( str ) { let temp ; let cnt = 0 ; let ans = new Array ( ) ; let bt = 1 << ( str . length - 1 ) ; let n = str . length ; for ( let i = 0 ; i < bt ; i ++ ) { temp = toBinary ( i ) + " " ; let j = 0 , x = n - temp . length , y ; while ( j < x ) { temp = " " + temp ; j ++ ; } j = 0 ; x = 0 ; y = - 1 ; let sp = " " , tp = " " ; let flag = 0 ; while ( j < n ) { sp += str [ j ] ; if ( temp [ j ] == ' ' ) { tp += sp + ' ' ; y = parseInt ( sp ) ; if ( ! primes [ y ] ) { flag = 1 ; break ; } sp = " " ; } j ++ ; } tp += sp ; if ( sp != " " ) { y = parseInt ( sp ) ; if ( ! primes [ y ] ) flag = 1 ; } if ( ! flag ) ans . push ( tp ) ; } if ( ans . length == 0 ) { document . write ( - 1 + " " ) ; } for ( let i of ans ) { document . write ( i + " " ) ; } } let str = " " ; sieve ( ) ; PrimeSplit ( str ) ;

Index/key variables: i, j, y
Accumulator variables: i, j, sp, tp
Iterator variables: i, j
Javascript program:
function countStableNum ( str , N ) { var count1 = Array . from ( Array ( N ) , ( ) => Array ( 10 ) ) ; var count2 = Array . from ( Array ( N ) , ( ) => Array ( 10 ) ) ; for ( var i = 0 ; i < N ; i ++ ) for ( var j = 0 ; j < 10 ; j ++ ) count1 [ i ] [ j ] = count2 [ i ] [ j ] = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( i != 0 ) { for ( var j = 0 ; j < 10 ; j ++ ) { count1 [ i ] [ j ] += count1 [ i - 1 ] [ j ] ; } } count1 [ i ] [ str [ i ] - ' ' ] ++ ; } for ( var i = N - 1 ; i >= 0 ; i -- ) { if ( i != N - 1 ) { for ( var j = 0 ; j < 10 ; j ++ ) { count2 [ i ] [ j ] += count2 [ i + 1 ] [ j ] ; } } count2 [ i ] [ str [ i ] - ' ' ] ++ ; } var ans = 0 ; for ( var i = 1 ; i < N - 1 ; i ++ ) { if ( str [ i ] == ' ' ) continue ; var c1 = count1 [ i - 1 ] [ str [ i ] - ' ' ] ; var c2 = count2 [ i + 1 ] [ str [ i ] - ' ' + 1 ] ; if ( c2 == 0 ) continue ; ans = ( ans + ( c1 * ( ( c2 * ( c2 - 1 ) / 2 ) ) ) ) ; } return ans ; } var str = " " ; var N = str . length ; document . write ( countStableNum ( str , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countSubsequenceUtil ( ind , sum , A , N , dp ) { if ( ind == N ) return 1 ; if ( dp [ ind ] [ sum ] != - 1 ) return dp [ ind ] [ sum ] ; if ( A [ ind ] <= sum ) { dp [ ind ] [ sum ] = countSubsequenceUtil ( ind + 1 , sum , A , N , dp ) + countSubsequenceUtil ( ind + 1 , sum - A [ ind ] , A , N , dp ) ; } else { dp [ ind ] [ sum ] = countSubsequenceUtil ( ind + 1 , sum , A , N , dp ) ; } return dp [ ind ] [ sum ] ; } function countSubsequence ( A , N , X ) { let dp = new Array ( N ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < X + 1 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return countSubsequenceUtil ( 0 , X , A , N , dp ) - 1 ; } let arr = [ 25 , 13 , 40 ] , X = 50 ; let N = arr . length ; document . write ( countSubsequence ( arr , N , X ) ) ;

Index/key variables: i, ind, j, sum
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function waysToDecode2 ( s ) { let n = s . length ; let dp = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; dp [ 0 ] = 1 ; if ( s [ 0 ] == ' ' ) return 0 ; dp [ 1 ] = ( ( s [ 0 ] == ' ' ) ? 9 : 1 ) ; for ( let i = 2 ; i <= n ; i ++ ) { let first = s [ i - 2 ] ; let second = s [ i - 1 ] ; if ( second == ' ' ) { dp [ i ] += 9 * dp [ i - 1 ] ; } else if ( second > ' ' ) dp [ i ] += dp [ i - 1 ] ; if ( first == ' ' first == ' ' ) { if ( second == ' ' ) { if ( first == ' ' ) dp [ i ] += 9 * dp [ i - 2 ] ; else if ( first == ' ' ) dp [ i ] += 6 * dp [ i - 2 ] ; } else if ( ( ( first - ' ' ) * 10 + ( second - ' ' ) ) <= 26 ) { dp [ i ] += dp [ i - 2 ] ; } } else if ( first == ' ' ) { if ( second == ' ' ) { dp [ i ] += 15 * dp [ i - 2 ] ; } else if ( second <= ' ' ) { dp [ i ] += 2 * dp [ i - 2 ] ; } else { dp [ i ] += dp [ i - 2 ] ; } } } return dp [ n ] ; } let str = " " ; document . write ( waysToDecode2 ( str . split ( ' ' ) ) + " " ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function goodLeteger ( arr , n , h , l , r ) { let dp = new Array ( n + 1 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < n + 1 ; i ++ ) for ( let j = 0 ; j < h ; j ++ ) dp [ i ] [ j ] = - 1 ; dp [ 0 ] [ 0 ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < h ; j ++ ) { if ( dp [ i ] [ j ] != - 1 ) { let h1 = ( j + arr [ i ] ) % h ; let h2 = ( j + arr [ i ] - 1 ) % h ; dp [ i + 1 ] [ h1 ] = Math . max ( dp [ i + 1 ] [ h1 ] , dp [ i ] [ j ] + ( ( h1 >= l && h1 <= r ) ? 1 : 0 ) ) ; dp [ i + 1 ] [ h2 ] = Math . max ( dp [ i + 1 ] [ h2 ] , dp [ i ] [ j ] + ( ( h2 >= l && h2 <= r ) ? 1 : 0 ) ) ; } } } let ans = 0 ; for ( let i = 0 ; i < h ; i ++ ) { if ( dp [ n ] [ i ] != - 1 ) ans = Math . max ( ans , dp [ n ] [ i ] ) ; } document . write ( ans + " " ) ; } let A = [ 16 , 17 , 14 , 20 , 20 , 11 , 22 ] ; let H = 24 ; let L = 21 ; let R = 23 ; let size = A . length ; goodLeteger ( A , size , H , L , R ) ;

Index/key variables: h1, h2, i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
class Query { constructor ( l , r ) { this . L = l ; this . R = r ; } } function fillPrefixArray ( arr , n , prefixArray ) { prefixArray [ 0 ] = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { prefixArray [ i ] = prefixArray [ i - 1 ] + arr [ i ] ; } else { prefixArray [ i ] = prefixArray [ i - 1 ] - arr [ i ] ; } } } function findResultUtil ( prefixArray , L , R ) { let result ; if ( L == 0 ) { result = prefixArray [ R ] ; } else { result = prefixArray [ R ] - prefixArray [ L - 1 ] ; } if ( L % 2 == 1 ) { result = result * ( - 1 ) ; } return result ; } function findResult ( arr , n , q , m ) { let prefixArray = new Array ( n ) ; fillPrefixArray ( arr , n , prefixArray ) ; for ( let i = 0 ; i < m ; i ++ ) { document . write ( findResultUtil ( prefixArray , q [ i ] . L , q [ i ] . R ) + " " ) ; } } let arr = [ 10 , 13 , 15 , 2 , 45 , 31 , 22 , 3 , 27 ] ; let n = arr . length ; let q = [ new Query ( 2 , 5 ) , new Query ( 6 , 8 ) , new Query ( 1 , 7 ) , new Query ( 4 , 8 ) , new Query ( 0 , 5 ) ] ; let m = q . length ; findResult ( arr , n , q , m ) ;

Index/key variables: R, i
Accumulator variables: i
Iterator variables: i
Class/struct names: Query
Javascript program:
function validSubArrLength ( arr , N , K ) { var dp = Array ( N + 1 ) ; var pos = 0 ; var ans = 0 ; var mx = 0 ; var pre = 0 ; var q = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { while ( q . length != 0 && arr [ q [ q . length - 1 ] ] < arr [ i ] ) q . pop ( ) ; q . push ( i ) ; if ( i == 0 ) { mx = arr [ i ] ; dp [ i ] = arr [ i ] ; } else if ( mx <= arr [ i ] ) { dp [ i ] = dp [ i - 1 ] + arr [ i ] ; mx = arr [ i ] ; } else { dp [ i ] = dp [ i - 1 ] + arr [ i ] ; } if ( pre == 0 ) pos = 0 ; else pos = pre - 1 ; while ( ( i - pre + 1 ) * mx - ( dp [ i ] - dp [ pos ] ) > K && pre < i ) { pos = pre ; pre ++ ; while ( q . length != 0 && q [ 0 ] < pre && pre < i ) { q . shift ( ) ; mx = arr [ q [ 0 ] ] ; } } ans = Math . max ( ans , i - pre + 1 ) ; } return ans ; } var N = 6 ; var K = 8 ; var arr = [ 2 , 7 , 1 , 3 , 4 , 5 ] ; document . write ( validSubArrLength ( arr , N , K ) ) ;

Index/key variables: i, pos
Accumulator variables: i, pre
Iterator variables: i
Javascript program:
function isKPartitionPossible ( arr , N , K ) { if ( K == 1 ) return true ; if ( N < K ) return false ; let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; if ( sum % K != 0 ) return false ; let target = sum / K ; let dp = Array . from ( { length : ( 1 << 15 ) } , ( _ , i ) => 0 ) ; for ( let i = 0 ; i < ( 1 << N ) ; i ++ ) dp [ i ] = - 1 ; dp [ 0 ] = 0 ; for ( let mask = 0 ; mask < ( 1 << N ) ; mask ++ ) { if ( dp [ mask ] == - 1 ) continue ; for ( let i = 0 ; i < N ; i ++ ) { if ( ( ( mask & ( 1 << i ) ) == 0 ) && dp [ mask ] + arr [ i ] <= target ) { dp [ mask ( 1 << i ) ] = ( dp [ mask ] + arr [ i ] ) % target ; } } } if ( dp [ ( 1 << N ) - 1 ] == 0 ) return true ; else return false ; } let arr = [ 2 , 1 , 4 , 5 , 3 , 3 ] ; let N = arr . length ; let K = 3 ; if ( isKPartitionPossible ( arr , N , K ) ) { document . write ( " " ) ; document . write ( " " ) ; } else { document . write ( " " ) ; document . write ( " " ) ; }

Index/key variables: i, mask
Accumulator variables: i, mask, sum
Iterator variables: i, mask
Javascript program:
let MAX = 1e18 ; let n , m ; let v = new Array ( 151 ) ; for ( let i = 0 ; i < 151 ; i ++ ) { v [ i ] = [ 0 , 0 ] ; } let dp = new Array ( 151 ) ; for ( let i = 0 ; i < 151 ; i ++ ) { dp [ i ] = new Array ( 151 ) ; } function min_operation ( i , j , val , x ) { if ( i == n - 1 && j == m - 1 ) { if ( val > v [ i ] [ j ] ) { return dp [ i ] [ j ] = MAX ; } else { return dp [ i ] [ j ] = v [ i ] [ j ] - val ; } } if ( i == n j == m ) { return dp [ i ] [ j ] = MAX ; } if ( dp [ i ] [ j ] != - 1 ) { return dp [ i ] [ j ] ; } if ( val > v [ i ] [ j ] ) { return dp [ i ] [ j ] = MAX ; } let tmp = v [ i ] [ j ] - val ; tmp += Math . min ( min_operation ( i + 1 , j , val + x , x ) , min_operation ( i , j + 1 , val + x , x ) ) ; return dp [ i ] [ j ] = tmp ; } function solve ( x ) { let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { let val = v [ i ] [ j ] - x * ( i + j ) ; for ( let k = 0 ; k < dp . length ; k ++ ) for ( let l = 0 ; l < dp [ k ] . length ; l ++ ) dp [ k ] [ l ] = - 1 ; val = min_operation ( 0 , 0 , val , x ) ; ans = Math . min ( ans , val ) ; } } return ans ; } let x = 3 ; n = 2 ; m = 2 ; v [ 0 ] = [ 15 , 153 ] ; v [ 1 ] = [ 135 , 17 ] ; document . write ( solve ( x ) + " " ) ;

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l, tmp
Iterator variables: i, j, k, l
Javascript program:
function Count ( S , m , n ) { let table = [ ] ; for ( let i = 0 ; i < m + 1 ; i ++ ) { table [ i ] = [ ] ; for ( let j = 0 ; j < n + 1 ; j ++ ) { table [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= n ; i ++ ) { table [ 0 ] [ i ] = Number . MAX_VALUE - 1 ; } for ( let i = 1 ; i <= m ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { if ( S [ i - 1 ] > j ) { table [ i ] [ j ] = table [ i - 1 ] [ j ] ; } else { table [ i ] [ j ] = Math . min ( table [ i - 1 ] [ j ] , table [ i ] [ j - S [ i - 1 ] ] + 1 ) ; } } } return table [ m ] [ n ] ; } let arr = [ 9 , 6 , 5 , 1 ] ; let m = arr . length ; document . write ( Count ( arr , m , 11 ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let INF = 10000000 ; function maximum ( A , B , C , D ) { return Math . max ( Math . max ( A , B ) , Math . max ( C , D ) ) ; } function maxProductUtil ( X , Y , A , B , dp ) { if ( X < 0 Y < 0 ) return - INF ; if ( dp [ X ] [ Y ] != - 1 ) return dp [ X ] [ Y ] ; dp [ X ] [ Y ] = maximum ( A [ X ] * B [ Y ] + maxProductUtil ( X - 1 , Y - 1 , A , B , dp ) , A [ X ] * B [ Y ] , maxProductUtil ( X - 1 , Y , A , B , dp ) , maxProductUtil ( X , Y - 1 , A , B , dp ) ) ; return dp [ X ] [ Y ] ; } function maxProduct ( A , N , B , M ) { let dp = new Array ( N ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return maxProductUtil ( N - 1 , M - 1 , A , B , dp ) ; } let a = [ - 2 , 6 , - 2 , - 5 ] ; let b = [ - 3 , 4 , - 2 , 8 ] ; let n = a . length ; let m = b . length ; document . write ( maxProduct ( a , n , b , m ) ) ;

Index/key variables: X, Y, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function twoStringsEquality ( s , t ) { var n = s . length ; var dp = Array . from ( Array ( n ) , ( ) => Array ( n + 1 ) . fill ( 0 ) ) ; if ( s [ n - 1 ] == t [ 0 ] ) dp [ n - 1 ] [ 1 ] = 1 ; if ( s [ n - 1 ] == t [ n - 1 ] ) dp [ n - 1 ] [ 0 ] = 1 ; for ( var i = n - 1 ; i > 0 ; i -- ) { for ( var j = 0 ; j <= n - i ; j ++ ) { if ( dp [ i ] [ j ] ) { if ( s [ i - 1 ] == t [ j ] ) dp [ i - 1 ] [ j + 1 ] = 1 ; if ( s [ i - 1 ] == t [ i + j - 1 ] ) dp [ i - 1 ] [ j ] = 1 ; } } } var ans = false ; for ( var i = 0 ; i <= n ; i ++ ) { if ( dp [ 0 ] [ i ] == 1 ) { ans = true ; break ; } } if ( ans == true ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } var S = " " ; var T = " " ; twoStringsEquality ( S , T ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: ans
Javascript program:
function findSum ( arr , n ) { var totalSum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { totalSum += arr [ i ] ; } var dp = Array . from ( Array ( 2 ) , ( ) => Array ( n ) ) ; for ( var i = 0 ; i < n ; i ++ ) { dp [ 0 ] [ i ] = 1 ; dp [ 1 ] [ i ] = arr [ i ] ; } for ( var i = 1 ; i < n ; i ++ ) { for ( var j = 0 ; j < i ; j ++ ) { if ( arr [ i ] > arr [ j ] ) { if ( dp [ 0 ] [ i ] < dp [ 0 ] [ j ] + 1 ) { dp [ 0 ] [ i ] = dp [ 0 ] [ j ] + 1 ; dp [ 1 ] [ i ] = dp [ 1 ] [ j ] + arr [ i ] ; } else if ( dp [ 0 ] [ i ] == dp [ 0 ] [ j ] + 1 ) { dp [ 1 ] [ i ] = Math . min ( dp [ 1 ] [ i ] , dp [ 1 ] [ j ] + arr [ i ] ) ; } } } } var maxm = 0 ; var subtractSum = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( dp [ 0 ] [ i ] > maxm ) { maxm = dp [ 0 ] [ i ] ; subtractSum = dp [ 1 ] [ i ] ; } else if ( dp [ 0 ] [ i ] == maxm ) { subtractSum = Math . min ( subtractSum , dp [ 1 ] [ i ] ) ; } } return totalSum - subtractSum ; } var arr = [ 4 , 6 , 1 , 2 , 3 , 8 ] ; var n = arr . length ; document . write ( findSum ( arr , n ) ) ;

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