dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function KthString ( A , B , K , dp ) { if ( A == 0 ) { let str = " " ; for ( let i = 0 ; i < B ; i ++ ) { str += ' ' ; } return str ; } if ( B == 0 ) { let str = " " ; for ( let i = 0 ; i < A ; i ++ ) { str += ' ' ; } return str ; } if ( K <= dp [ A - 1 ] [ B ] ) { return " " + KthString ( A - 1 , B , K , dp ) ; } else { return " " + KthString ( A , B - 1 , K - dp [ A - 1 ] [ B ] , dp ) ; } } function KthStringUtil ( A , B , K ) { let dp = new Array ( A + 1 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( B + 1 ) . fill ( 0 ) ; } dp [ 0 ] [ 0 ] = 1 ; for ( let i = 0 ; i <= A ; ++ i ) { for ( let j = 0 ; j <= B ; ++ j ) { if ( i > 0 ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ; } if ( j > 0 ) { dp [ i ] [ j ] += dp [ i ] [ j - 1 ] ; } } } document . write ( KthString ( A , B , K , dp ) ) ; return 0 ; } let A = 3 , B = 3 , K = 7 ; KthStringUtil ( A , B , K ) ;

Index/key variables: B, i, j
Accumulator variables: i, str
Iterator variables: i, j
Javascript program:
function combinationsPossible ( N , idx , prev , val , K , dp ) { if ( val > K ) { return 0 ; } if ( dp [ val ] [ idx ] [ prev ] != - 1 ) { return dp [ val ] [ idx ] [ prev ] ; } if ( idx == N - 1 ) { if ( val == K ) { return 1 ; } return 0 ; } let ans = 0 ; if ( prev == 1 ) { ans += combinationsPossible ( N , idx + 1 , 1 , val + 1 , K , dp ) ; ans += combinationsPossible ( N , idx + 1 , 0 , val , K , dp ) ; } else { ans += combinationsPossible ( N , idx + 1 , 1 , val , K , dp ) ; ans += combinationsPossible ( N , idx + 1 , 0 , val , K , dp ) ; } return dp [ val ] [ idx ] [ prev ] = ans ; } let N = 5 ; let K = 3 ; let dp = new Array ( K + 1 ) ; for ( i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( N + 1 ) ; } for ( i = 0 ; i < dp . length ; i ++ ) { for ( j = 0 ; j < dp [ 0 ] . length ; j ++ ) { dp [ i ] [ j ] = new Array ( 2 ) . fill ( - 1 ) ; } } document . write ( combinationsPossible ( N , 0 , 0 , 0 , K , dp ) + combinationsPossible ( N , 0 , 1 , 0 , K , dp ) ) ;

Index/key variables: i, idx, j, prev, val
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function countOfWays ( arr , N ) { let pre = new Array ( N + 1 ) . fill ( 0 ) ; for ( let i = 0 ; i < N ; i ++ ) { pre [ i + 1 ] = pre [ i ] + arr [ i ] ; } let dp = new Array ( N + 2 ) . fill ( 0 ) . map ( ( ) => new Array ( N + 2 ) . fill ( 0 ) ) ; dp [ 1 ] [ 0 ] ++ ; let ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = N ; j >= 1 ; j -- ) { dp [ j + 1 ] [ pre [ i + 1 ] % ( j + 1 ) ] += dp [ j ] [ pre [ i + 1 ] % j ] ; if ( i == N - 1 ) { ans += dp [ j ] [ pre [ i + 1 ] % j ] ; } } } return ans ; } let arr = [ 1 , 2 , 3 , 4 ] ; let N = arr . length ; document . write ( countOfWays ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
let MAX = 500 ; let lookup = new Array ( MAX ) . fill ( 0 ) . map ( ( ) => new Array ( MAX ) . fill ( 0 ) ) ; class Query { constructor ( l , r ) { this . L = l ; this . R = r ; } } function preprocess ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) lookup [ i ] [ 0 ] = i ; for ( let j = 1 ; 1 << j <= n ; j ++ ) { for ( let i = 0 ; i + ( 1 << j ) - 1 < n ; i ++ ) { if ( arr [ lookup [ i ] [ j - 1 ] ] < arr [ lookup [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ] ] ) lookup [ i ] [ j ] = lookup [ i ] [ j - 1 ] ; else lookup [ i ] [ j ] = lookup [ i + ( 1 << ( j - 1 ) ) ] [ j - 1 ] ; } } } function query ( arr , L , R ) { let j = Math . floor ( Math . log ( R - L + 1 ) ) ; if ( arr [ lookup [ L ] [ j ] ] <= arr [ lookup [ R - ( 1 << j ) + 1 ] [ j ] ] ) return arr [ lookup [ L ] [ j ] ] ; else return arr [ lookup [ R - ( 1 << j ) + 1 ] [ j ] ] ; } function Min_difference ( arr , n , q , m ) { preprocess ( arr , n ) ; for ( let i = 0 ; i < m ; i ++ ) { let L = q [ i ] . L , R = q [ i ] . R ; document . write ( query ( arr , L , R - 1 ) + " " ) ; } } function minimumDifference ( arr , q , N , m ) { let diff = new Array ( N ) ; for ( let i = 0 ; i < N - 1 ; i ++ ) diff [ i ] = Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; Min_difference ( diff , N - 1 , q , m ) ; } let arr = [ 2 , 6 , 1 , 8 , 3 , 4 ] ; let N = arr . length ; let Q = [ new Query ( 0 , 3 ) , new Query ( 1 , 5 ) , new Query ( 4 , 5 ) ] ; let M = Q . length ; minimumDifference ( arr , Q , N , M ) ;

Index/key variables: L, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Query
Javascript program:
const MOD = 1e9 + 7 ; function numTilings ( N ) { if ( N < 3 ) { return N ; } let dp = Array ( N + 1 ) . fill ( ) . map ( ( ) => Array ( 3 ) . fill ( 0 ) ) dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = 1 ; dp [ 1 ] [ 1 ] = dp [ 1 ] [ 2 ] = 1 ; for ( let i = 2 ; i <= N ; i ++ ) { dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 2 ] [ 0 ] + dp [ i - 2 ] [ 1 ] + dp [ i - 2 ] [ 2 ] ) % MOD ; dp [ i ] [ 1 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 2 ] ) % MOD ; dp [ i ] [ 2 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] ) % MOD ; } return dp [ N ] [ 0 ] ; } let N = 3 ; document . write ( numTilings ( N ) ) ;

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Javascript program:
let dp = new Map ( ) ; function countStrings ( N ) { if ( N == 1 ) return 0 ; if ( dp . has ( N ) ) return dp . get ( N ) ; let ret = 0 ; for ( let div = 1 ; div <= Math . sqrt ( N ) ; div ++ ) { if ( N % div == 0 ) { ret += ( 1 << div ) - countStrings ( div ) ; let div2 = N / div ; if ( div2 != div && div != 1 ) ret += ( 1 << div2 ) - countStrings ( div2 ) ; } } dp [ N ] = ret ; return ret ; } let N = 6 ; document . write ( countStrings ( N ) + " " ) ;

Index/key variables: N
Accumulator variables: div, ret
Iterator variables: div
Javascript program:
const mod = 1e9 + 7 ; function countOfNumbers ( N ) { let ans = 1 ; for ( let index = 1 ; index <= N ; ++ index ) { let choices = 0 ; for ( let digit = 1 ; digit <= 9 ; ++ digit ) { if ( index % digit == 0 ) { ++ choices ; } } ans = ( ans * 1 * choices ) % mod ; } document . write ( ans ) ; } let N = 5 ; countOfNumbers ( N ) ;

Iterator variables: digit, index
Javascript program:
function dfs ( arr , left , K ) { let q = 0 ; if ( left == 0 ) { for ( let i = 1 ; i < K ; ++ i ) { if ( arr [ i ] > 0 ) { arr [ i ] -- ; q = Math . max ( q , 1 + dfs ( arr , K - i , K ) ) ; arr [ i ] ++ ; } } } else { for ( let i = 1 ; i < K ; ++ i ) { if ( arr [ i ] > 0 ) { arr [ i ] -- ; let nleft = ( i <= left ? left - i : K + left - i ) ; q = Math . max ( q , dfs ( arr , nleft , K ) ) ; arr [ i ] ++ ; } } } return q ; } function maxGroups ( K , arr , n ) { let V = new Array ( K ) . fill ( 0 ) ; for ( let x = 0 ; x < n ; x ++ ) V [ arr [ x ] % K ] ++ ; let ans = V [ 0 ] + dfs ( V , 0 , K ) ; return ans ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; let K = 3 ; document . write ( maxGroups ( K , arr , n ) )

Index/key variables: i, x
Accumulator variables: x
Iterator variables: i, x
Javascript program:
function findMaxJumps ( arr , N ) { let dp = new Array ( N ) . fill ( 0 ) ; let ans = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { dp [ i ] = arr [ i ] ; let j = i + arr [ i ] ; if ( j < N ) { dp [ i ] = dp [ i ] + dp [ j ] ; } ans = Math . max ( ans , dp [ i ] ) ; } document . write ( ans ) ; } let arr = [ 2 , 3 , 5 , 7 , 9 ] ; let N = arr . length ; findMaxJumps ( arr , N ) ;

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Javascript program:
function longestSubsequence ( arr , N ) { let dp = Array ( N ) . fill ( ) . map ( ( ) => Array ( N + 1 ) . fill ( - 1 ) ) ; for ( let i = 0 ; i < N ; ++ i ) { dp [ i ] [ 0 ] = 0 ; } dp [ 0 ] [ 1 ] = ( arr [ 0 ] >= 0 ? arr [ 0 ] : - 1 ) ; for ( let i = 1 ; i < N ; ++ i ) { for ( let j = 1 ; j <= ( i + 1 ) ; ++ j ) { if ( dp [ i - 1 ] [ j ] != - 1 ) { dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j ] ) ; } if ( dp [ i - 1 ] [ j - 1 ] >= 0 && dp [ i - 1 ] [ j - 1 ] + arr [ i ] >= 0 ) { dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j - 1 ] + arr [ i ] ) ; } } } let ans = 0 ; for ( let j = 0 ; j <= N ; ++ j ) { if ( dp [ N - 1 ] [ j ] >= 0 ) { ans = j ; } } document . write ( ans ) ; } let arr = [ 4 , - 4 , 1 , - 3 , 1 , - 3 ] ; let N = arr . length ; longestSubsequence ( arr , N ) ;

Index/key variables: i, j
Iterator variables: i, j
Javascript program:
function Count ( N , L , R ) { let dp = new Array ( N ) . fill ( 0 ) . map ( ( ) => new Array ( R - L + 1 ) . fill ( 0 ) ) ; let ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = 1 ; } for ( let i = 1 ; i < dp [ 0 ] . length ; i ++ ) { dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 1 ; } ans = dp [ 0 ] [ R - L ] ; for ( let i = 1 ; i < N ; i ++ ) { for ( let j = 1 ; j < dp [ 0 ] . length ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] ; } ans += dp [ i ] [ R - L ] ; } return ans ; } let N = 3 ; let L = 6 ; let R = 9 ; document . write ( Count ( N , L , R ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function largestCommonSubarray ( arr , n , m ) { let dp = Array ( n ) . fill ( ) . map ( ( ) => Array ( m + 1 ) ) ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { dp [ i ] [ arr [ i ] [ j ] ] = j ; } } let ans = 1 ; let len = 1 ; for ( let i = 1 ; i < m ; i ++ ) { let check = true ; for ( let j = 1 ; j < n ; j ++ ) { if ( dp [ j ] [ arr [ 0 ] [ i - 1 ] ] + 1 != dp [ j ] [ arr [ 0 ] [ i ] ] ) { check = false ; break ; } } if ( check ) { len ++ ; ans = Math . max ( ans , len ) ; } else { len = 1 ; } } return ans ; } let n = 4 ; let m = 5 ; let arr = [ [ 4 , 5 , 1 , 2 , 3 , 6 , 7 ] , [ 1 , 2 , 4 , 5 , 7 , 6 , 3 ] , [ 2 , 7 , 3 , 4 , 5 , 1 , 6 ] ] ; let N = arr . length ; let M = arr [ 0 ] . length ; document . write ( largestCommonSubarray ( arr , N , M ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, len
Iterator variables: i, j
Boolean variables: check
Javascript program:
function MaximumSum ( a , b , n ) { let dp = new Array ( n ) . fill ( 0 ) . map ( ( ) => new Array ( 2 ) ) ; dp [ 0 ] [ 0 ] = a [ 0 ] ; dp [ 0 ] [ 1 ] = b [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { dp [ i ] [ 0 ] = Math . max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + a [ i ] ; dp [ i ] [ 1 ] = Math . max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) ; if ( i - 2 >= 0 ) { dp [ i ] [ 1 ] = Math . max ( dp [ i ] [ 1 ] , Math . max ( dp [ i - 2 ] [ 0 ] , dp [ i - 2 ] [ 1 ] ) + b [ i ] ) ; } else { dp [ i ] [ 1 ] = Math . max ( dp [ i ] [ 1 ] , b [ i ] ) ; } } return Math . max ( dp [ n - 1 ] [ 0 ] , dp [ n - 1 ] [ 1 ] ) ; } let A = [ 10 , 1 , 10 , 10 ] ; let B = [ 5 , 50 , 1 , 5 ] ; let N = A . length ; document . write ( MaximumSum ( A , B , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function KvisibleFromLeft ( N , K ) { if ( N == K ) return 1 ; if ( K == 1 ) { let ans = 1 ; for ( let i = 1 ; i < N ; i ++ ) ans *= i ; return ans ; } return KvisibleFromLeft ( N - 1 , K - 1 ) + ( N - 1 ) * KvisibleFromLeft ( N - 1 , K ) ; } let N = 5 , K = 2 ; document . write ( KvisibleFromLeft ( N , K ) + " " ) ;

Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function minimumDeletions ( A , N ) { let ans = Number . MAX_SAFE_INTEGER ; for ( let i = 1 ; i < ( 1 << N ) ; i ++ ) { let temp = [ ] ; for ( let j = 0 ; j < N ; j ++ ) { if ( ( i & ( 1 << j ) ) != 0 ) { temp . push ( A [ j ] ) ; } } let flag = 0 ; for ( let j = 1 ; j < temp . length ; j ++ ) if ( temp [ j ] < temp [ j - 1 ] ) flag = 1 ; for ( let j = 1 ; j < temp . length - 1 ; j ++ ) if ( temp [ j ] - temp [ j - 1 ] > temp [ j + 1 ] - temp [ j ] ) flag = 1 ; if ( flag == 0 ) { ans = Math . min ( ans , N - temp . length ) ; } } return ans ; } let A = [ 1 , 4 , 5 , 7 , 20 , 21 ] ; let N = A . length ; document . write ( minimumDeletions ( A , N ) + " " ) ;

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var MAX = 100001 ; function minimumDeletions ( A , N ) { var dp = new Array ( N , MAX ) ; var pref = new Array ( N , MAX ) ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < MAX ; j ++ ) { dp [ i , j ] = 0 ; pref [ i , j ] = 0 ; } } for ( var i = 0 ; i < N ; i ++ ) { dp [ i , 0 ] = 1 ; for ( var j = i - 1 ; j >= 0 ; j -- ) { if ( A [ i ] >= A [ j ] ) { var diff = A [ i ] - A [ j ] ; dp [ i ] = Math . max ( dp [ i , diff ] , pref [ j , diff ] + 1 ) ; } } pref [ i , 0 ] = dp [ i , 0 ] ; for ( var j = 1 ; j < MAX ; j ++ ) pref [ i , j ] = Math . max ( dp [ i , j ] , pref [ i , j - 1 ] ) ; } var maxSetSize = - 1 ; for ( var i = 0 ; i < MAX ; i ++ ) maxSetSize = Math . max ( maxSetSize , dp [ N - 1 , i ] ) ; return N - maxSetSize ; } var A = [ 1 , 4 , 5 , 7 , 20 , 21 ] ; var N = A . length ; document . write ( minimumDeletions ( A , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maximumSum ( A , N , K , D ) { let ans = 0 ; for ( let i = 0 ; i < ( 1 << N ) ; i ++ ) { let sum = 0 ; let c = 0 ; for ( let j = 0 ; j < N ; j ++ ) { if ( i >> j & 1 ) { sum += A [ j ] ; c ++ ; } } if ( sum % D == 0 && c <= K ) ans = Math . max ( ans , sum ) ; } return ans ; } let N = 5 , K = 3 , D = 7 ; let A = [ 1 , 11 , 5 , 5 , 18 ] ; document . write ( maximumSum ( A , N , K , D ) + " " ) ;

Index/key variables: j
Accumulator variables: c, i, j, sum
Iterator variables: i, j
Javascript program:
function longestSubsequence ( X , Y ) { let n = X . length ; let m = Y . length ; let mat = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { mat [ i ] = new Array ( m + 1 ) ; for ( let j = 0 ; j < m + 1 ; j ++ ) { if ( i == 0 j == 0 ) mat [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i < n + 1 ; i ++ ) { for ( let j = 1 ; j < m + 1 ; j ++ ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { mat [ i ] [ j ] = 1 + mat [ i - 1 ] [ j - 1 ] ; } else { mat [ i ] [ j ] = mat [ i - 1 ] [ j ] ; } } } let len = 0 , col = 0 ; for ( let i = 0 ; i < m + 1 ; i ++ ) { if ( mat [ n ] [ i ] > len ) { len = mat [ n ] [ i ] ; col = i ; } } let res = " " ; let i = n ; let j = col ; while ( len > 0 ) { if ( X [ i - 1 ] == Y [ j - 1 ] ) { res = X [ i - 1 ] + res ; i -- ; j -- ; len -- ; } else { i -- ; } } return res ; } let X = " " ; let Y = " " ; document . write ( longestSubsequence ( X , Y ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j, len
Iterator variables: i, j
Javascript program:
function countPairs ( arr ) { let N = arr . length ; let ans = 0 ; let M = new Map ( ) ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( M . has ( arr [ i ] ) ) { M . get ( arr [ i ] ) . push ( i ) ; } else { M . set ( arr [ i ] , [ i ] ) } } for ( let it of M ) { let v = it [ 1 ] ; let sum = 0 ; for ( let j = 0 ; j < v . length ; j ++ ) { ans += sum * ( N - v [ j ] ) ; sum += v [ j ] + 1 ; } } document . write ( ans ) ; } let arr = [ 1 , 2 , 1 , 1 ] ; countPairs ( arr ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j, sum
Iterator variables: i, it, j
Javascript program:
function countAlternatingSubstrings ( S , N ) { var dp = new Array ( 2 ) ; dp [ 0 ] = Array ( N ) . fill ( 0 ) ; dp [ 1 ] = Array ( N ) . fill ( 0 ) ; var i ; for ( i = N - 1 ; i >= 0 ; i -- ) { if ( i == N - 1 ) { if ( S [ i ] == ' ' ) dp [ 1 ] [ i ] = 1 ; else dp [ 0 ] [ i ] = 1 ; } else { if ( S [ i ] == ' ' ) dp [ 0 ] [ i ] = 1 + dp [ 1 ] [ i + 1 ] ; else dp [ 1 ] [ i ] = 1 + dp [ 0 ] [ i + 1 ] ; } } var ans = 0 ; for ( i = 0 ; i < N ; i ++ ) { ans += Math . max ( dp [ 0 ] [ i ] , dp [ 1 ] [ i ] ) ; } return ans ; } var S = " " ; var N = S . length ; document . write ( countAlternatingSubstrings ( S , N ) ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function solve ( A , N , K ) { let sum = 0 ; let c = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sum += A [ i ] ; if ( A [ i ] == 0 ) c ++ ; } if ( K > sum || ( sum + K ) % 2 ) return 0 ; sum = ( sum + K ) / 2 ; let dp = new Array ( N + 1 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( sum + 1 ) ; } for ( let i = 0 ; i <= sum ; i ++ ) dp [ 0 ] [ i ] = 0 ; for ( let i = 0 ; i <= N ; i ++ ) dp [ i ] [ 0 ] = 1 ; for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = 1 ; j <= sum ; j ++ ) { if ( A [ i - 1 ] <= j && A [ i - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - A [ i - 1 ] ] ; else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; } } return dp [ N ] [ sum ] + Math . pow ( 2 , c ) ; } let A = [ 1 , 1 , 2 , 3 ] ; let N = A . length ; let K = 3 ; document . write ( solve ( A , N , K ) ) ;

Index/key variables: N, i, j, sum
Accumulator variables: c, i, j, sum
Iterator variables: i, j
Javascript program:
function maximizeAnd ( i , mask , A , B , N , dp ) { if ( i == N ) return 0 ; if ( dp [ i ] [ mask ] != - 1 ) return dp [ i ] [ mask ] ; for ( var j = 0 ; j < N ; ++ j ) { if ( ! ( mask & ( 1 << j ) ) ) { dp [ i ] [ mask ] = Math . max ( dp [ i ] [ mask ] , ( A [ i ] & B [ j ] ) + maximizeAnd ( i + 1 , mask | ( 1 << j ) , A , B , N , dp ) ) ; } } return dp [ i ] [ mask ] ; } function maximizeAndUtil ( A , B , N ) { var dp = Array . from ( Array ( N ) , ( ) => Array ( 1 << N + 1 ) . fill ( - 1 ) ) ; return maximizeAnd ( 0 , 0 , A , B , N , dp ) ; } var A = [ 3 , 5 , 7 , 11 ] ; var B = [ 2 , 6 , 10 , 12 ] ; var N = A . length document . write ( maximizeAndUtil ( A , B , N ) ) ;

Index/key variables: i, j, mask
Iterator variables: j
Javascript program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int numberOfWays ( int N ) { int DP [ ] [ ] = new int [ N + 1 ] [ 5 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { for ( int j = 0 ; j < 5 ; j ++ ) { DP [ i ] [ j ] = 0 ; } } DP [ 1 ] [ 1 ] = 1 ; DP [ 1 ] [ 2 ] = 1 ; DP [ 1 ] [ 3 ] = 1 ; DP [ 1 ] [ 4 ] = 1 ; for ( int i = 2 ; i <= N ; i ++ ) { if ( i - 1 > 0 && DP [ i - 1 ] [ 1 ] > 0 ) DP [ i ] [ 1 ] = DP [ i - 1 ] [ 4 ] ; if ( i - 2 > 0 && DP [ i - 2 ] [ 2 ] > 0 ) DP [ i ] [ 2 ] = DP [ i - 2 ] [ 4 ] ; if ( i - 3 > 0 && DP [ i - 3 ] [ 3 ] > 0 ) DP [ i ] [ 3 ] = DP [ i - 3 ] [ 4 ] ; DP [ i ] [ 4 ] = ( DP [ i ] [ 1 ] + DP [ i ] [ 2 ] + DP [ i ] [ 3 ] ) ; } return DP [ N ] [ 4 ] ; } public static void main ( String [ ] args ) { int N = 15 ; System . out . print ( numberOfWays ( N ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Javascript program:
function maximumSum ( arr , n ) { let preSum = Array . from ( { length : n } , ( _ , i ) => 0 ) ; let sum = 0 ; let maxSum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum = Math . max ( arr [ i ] , sum + arr [ i ] ) ; maxSum = Math . max ( maxSum , sum ) ; preSum [ i ] = maxSum ; } sum = 0 ; maxSum = 0 ; let postSum = Array . from ( { length : n + 1 } , ( _ , i ) => 0 ) ; for ( let i = n - 1 ; i >= 0 ; i -- ) { sum = Math . max ( arr [ i ] , sum + arr [ i ] ) ; maxSum = Math . max ( maxSum , sum ) ; postSum [ i ] = maxSum ; } let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { ans = Math . max ( ans , preSum [ i ] + postSum [ i + 1 ] ) ; } document . write ( ans ) ; } let arr = [ 7 , 6 , - 1 , - 4 , - 5 , 7 , 1 ] ; maximumSum ( arr , arr . length ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function lisOtimised ( s ) { let dp = new Array ( 30 ) . fill ( 0 ) ; let N = s . length ; let lis = Number . MIN_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { let val = s . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ; let curr = 0 ; for ( let j = 0 ; j < val ; j ++ ) { curr = Math . max ( curr , dp [ j ] ) ; } curr ++ ; lis = Math . max ( lis , curr ) ; dp [ val ] = Math . max ( dp [ val ] , curr ) ; } return lis ; } let s = " " ; document . write ( lisOtimised ( s ) ) ;

Index/key variables: j, val
Accumulator variables: curr, i, j
Iterator variables: i, j
Javascript program:
var max1 = 1000000000 ; function MinimumLength ( A , N , K ) { 0 A . sort ( ) ; var suffix = Array ( N + 1 ) . fill ( 0 ) ; var i ; for ( i = N - 1 ; i >= 0 ; i -- ) suffix [ i ] = suffix [ i + 1 ] + A [ i ] ; var dp = new Array ( N + 1 ) ; for ( i = 0 ; i < N + 1 ; i ++ ) dp [ i ] = new Array ( K + 1 ) ; var j ; for ( i = 0 ; i <= N ; i ++ ) { for ( j = 0 ; j <= K ; j ++ ) { dp [ i ] [ j ] = max1 ; } } ; dp [ N ] [ 0 ] = 0 ; for ( i = N - 1 ; i >= 0 ; i -- ) { for ( j = K ; j >= 0 ; j -- ) { if ( j <= A [ i ] ) { dp [ i ] [ j ] = A [ i ] ; continue ; } if ( dp [ i + 1 ] [ j - A [ i ] ] == max1 ) dp [ i ] [ j ] = max1 ; else dp [ i ] [ j ] = Math . min ( dp [ i + 1 ] [ j ] , dp [ i + 1 ] [ j - A [ i ] ] + A [ i ] ) ; } } for ( i = N - 1 ; i >= 0 ; i -- ) { if ( suffix [ i ] - dp [ i ] [ K ] >= K ) { return N - i ; } } return - 1 ; } var arr = [ 7 , 4 , 5 , 6 , 8 ] ; var K = 13 ; var N = arr . length ; document . write ( MinimumLength ( arr , N , K ) ) ;

Index/key variables: K, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let size = 20 ; var dp = new Array ( size ) . fill ( 0 ) ; let ans = 0 ; function insertVector ( mask ) { for ( let i = 0 ; i < 20 ; i ++ ) { if ( ( mask & 1 << i ) == 0 ) continue ; if ( dp [ i ] == 0 ) { dp [ i ] = mask ; ++ ans ; return ; } mask ^= dp [ i ] ; } } function maxSizeSet ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { insertVector ( arr [ i ] ) ; } document . write ( 1 << ans ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; maxSizeSet ( arr , N ) ;

Index/key variables: i
Accumulator variables: i, mask
Iterator variables: i
Javascript program:
function maxSum ( arr , N , K ) { let dp = [ ] ; for ( let i = 0 ; i < N + 2 ; i ++ ) { dp [ i ] = 0 ; } let maxval = 0 ; for ( let i = N - 1 ; i >= 0 ; i -- ) { if ( ( i + K * arr [ i ] ) >= N ) { dp [ i ] = arr [ i ] ; } else { dp [ i ] = dp [ i + K * arr [ i ] ] + arr [ i ] ; } maxval = Math . max ( maxval , dp [ i ] ) ; } document . write ( maxval ) ; } let arr = [ 2 , 1 , 3 , 1 , 2 ] ; let N = arr . length ; let K = 3 ; maxSum ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxSubmatrixSum ( matrix ) { var r = matrix . length ; var c = matrix [ 0 ] . length ; var maxSubmatrix = 0 ; for ( i = 0 ; i < r ; i ++ ) { for ( j = 0 ; j < c ; j ++ ) { for ( k = i ; k < r ; k ++ ) { for ( l = j ; l < c ; l ++ ) { var sumSubmatrix = 0 ; for ( m = i ; m <= k ; m ++ ) { for ( n = j ; n <= l ; n ++ ) { sumSubmatrix += matrix [ m ] [ n ] ; } } maxSubmatrix = Math . max ( maxSubmatrix , sumSubmatrix ) ; } } } } document . write ( maxSubmatrix ) ; } var matrix = [ [ 0 , - 2 , - 7 , 0 ] , [ 9 , 2 , - 6 , 2 ] , [ - 4 , 1 , - 4 , 1 ] , [ - 1 , 8 , 0 , - 2 ] ] ; maxSubmatrixSum ( matrix ) ;

Index/key variables: m, n
Accumulator variables: i, j, k, l, m, n, sumSubmatrix
Iterator variables: i, j, k, l, m, n
Javascript program:
function maximumSubsetSum ( arr1 , arr2 , length ) { let dp = new Array ( length ) . fill ( 0 ) ; ; if ( length == 1 ) { document . write ( Math . max ( arr1 [ 0 ] , arr2 [ 0 ] ) ) ; return ; } if ( length == 2 ) { document . write ( Math . max ( Math . max ( arr1 [ 1 ] , arr2 [ 1 ] ) , Math . max ( arr1 [ 0 ] , arr2 [ 0 ] ) ) ) ; return ; } else { dp [ 0 ] = Math . max ( arr1 [ 0 ] , arr2 [ 0 ] ) ; dp [ 1 ] = Math . max ( Math . max ( arr1 [ 1 ] , arr2 [ 1 ] ) , Math . max ( arr1 [ 0 ] , arr2 [ 0 ] ) ) ; let index = 2 ; while ( index < length ) { dp [ index ] = Math . max ( Math . max ( arr1 [ index ] , arr2 [ index ] ) , Math . max ( Math . max ( arr1 [ index ] + dp [ index - 2 ] , arr2 [ index ] + dp [ index - 2 ] ) , dp [ index - 1 ] ) ) ; ++ index ; } document . write ( dp [ length - 1 ] ) ; } } let arr1 = [ - 1 , - 2 , 4 , - 4 , 5 ] ; let arr2 = [ - 1 , - 2 , - 3 , 4 , 10 ] ; let length = arr1 . length ; maximumSubsetSum ( arr1 , arr2 , length ) ;

Index/key variables: index
Javascript program:
function minAtEachIndex ( n , arr ) { var dp1 = Array ( n ) ; var dp2 = Array ( n ) ; var i ; dp1 [ 0 ] = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) dp1 [ i ] = Math . min ( arr [ i ] , dp1 [ i - 1 ] + 1 ) ; dp2 [ n - 1 ] = arr [ n - 1 ] ; for ( i = n - 2 ; i >= 0 ; i -- ) dp2 [ i ] = Math . min ( arr [ i ] , dp2 [ i + 1 ] + 1 ) ; var v = [ ] ; for ( i = 0 ; i < n ; i ++ ) v . push ( Math . min ( dp1 [ i ] , dp2 [ i ] ) ) ; v . forEach ( x => { document . write ( x + " " ) ; } ) ; } var arr = [ 1 , 4 , 2 , 5 , 3 ] ; var N = arr . length ; minAtEachIndex ( N , arr ) ;

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