dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
var N = 10 ; var dp = Array . from ( Array ( N ) , ( ) => Array ( N ) . fill ( - 1 ) ) ; function findLongest ( a , n , present , previous ) { if ( present == n ) { return 0 ; } else if ( previous != - 1 ) { if ( dp [ present ] [ previous ] != - 1 ) return dp [ present ] [ previous ] ; } var ans = 0 ; if ( previous == - 1 ) { ans = 1 + findLongest ( a , n , present + 1 , present ) ; ans = Math . max ( ans , findLongest ( a , n , present + 1 , previous ) ) ; } else { var h1 = a [ previous ] [ 0 ] ; var h2 = a [ present ] [ 0 ] ; var w1 = a [ previous ] [ 1 ] ; var w2 = a [ present ] [ 1 ] ; if ( ( h1 <= h2 && w1 <= w2 ) ) { ans = Math . max ( ans , findLongest ( a , n , present + 1 , previous ) ) ; } else { ans = 1 + findLongest ( a , n , present + 1 , present ) ; ans = Math . max ( ans , findLongest ( a , n , present + 1 , previous ) ) ; } } return dp [ present ] [ previous ] = ans ; } function getLongest ( a , n ) { dp = Array . from ( Array ( N ) , ( ) => Array ( N ) . fill ( - 1 ) ) ; a . sort ( ( a , b ) => a - b ) ; var ans = findLongest ( a , n , 0 , - 1 ) ; return ans ; } var a = [ [ 1 , 5 ] , [ 2 , 4 ] , [ 1 , 1 ] , [ 3 , 3 ] ] ; var n = a . length ; document . write ( getLongest ( a , n ) ) ;

Index/key variables: present, previous
Javascript program:
let N , MAX ; let lpd ; function preCompute ( ) { lpd = new Array ( MAX + 1 ) ; for ( let i = 0 ; i < lpd . length ; i ++ ) { lpd [ i ] = 0 ; } lpd [ 0 ] = lpd [ 1 ] = 1 ; for ( let i = 2 ; i * i <= MAX ; i ++ ) { for ( let j = i * 2 ; j <= MAX ; j += i ) { if ( lpd [ j ] == 0 ) { lpd [ j ] = i ; } } } for ( let i = 2 ; i <= MAX ; i ++ ) { if ( lpd [ i ] == 0 ) { lpd [ i ] = i ; } } } function maxLengthSubsequence ( arr , n ) { let dp = new Array ( N ) ; let pos = new Map ( ) ; for ( let i = 0 ; i <= n ; i ++ ) dp [ i ] = 1 ; for ( let i = 0 ; i <= n ; i ++ ) { while ( arr [ i ] > 1 ) { let p = lpd [ arr [ i ] ] ; if ( pos . has ( p ) ) { dp [ i ] = Math . max ( dp [ i ] , 1 + dp [ pos . get ( p ) ] ) ; } pos . set ( p , i ) ; while ( arr [ i ] % p == 0 ) arr [ i ] = Math . floor ( arr [ i ] / p ) ; } } let ans = Math . max ( ... dp ) ; return ans ; } let arr = [ 13 , 2 , 8 , 6 , 3 , 1 , 9 ] ; N = arr . length ; MAX = Math . max ( ... arr ) ; preCompute ( ) ; document . write ( maxLengthSubsequence ( arr , N - 1 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MAX = 10 ; let F = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { F [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { F [ i ] [ j ] = new Array ( MAX ) ; for ( let k = 0 ; k < MAX ; k ++ ) { F [ i ] [ j ] [ k ] = - 1 ; } } } function noOfAssignments ( s , n , i , c_x , c_y ) { if ( F [ i ] [ c_x ] [ c_y ] != - 1 ) return F [ i ] [ c_x ] [ c_y ] ; if ( i == n ) { F [ i ] [ c_x ] [ c_y ] = ( c_x == 0 && c_y == 0 ) ? 1 : 0 ; return F [ i ] [ c_x ] [ c_y ] ; } if ( s . charAt ( i ) == ' ' ) { F [ i ] [ c_x ] [ c_y ] = noOfAssignments ( s , n , i + 1 , c_x + 1 , c_y ) + noOfAssignments ( s , n , i + 1 , c_x , c_y + 1 ) ; return F [ i ] [ c_x ] [ c_y ] ; } F [ i ] [ c_x ] [ c_y ] = 0 ; if ( c_x != 0 ) F [ i ] [ c_x ] [ c_y ] += noOfAssignments ( s , n , i + 1 , c_x - 1 , c_y ) ; if ( c_y != 0 ) F [ i ] [ c_x ] [ c_y ] += noOfAssignments ( s , n , i + 1 , c_x , c_y - 1 ) ; return F [ i ] [ c_x ] [ c_y ] ; } let s = " " ; let n = s . length ; document . write ( noOfAssignments ( s , n , 0 , 0 , 0 ) ) ;

Index/key variables: c_x, c_y, i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function lds ( arr , n ) { let lds = new Array ( n ) ; lds [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { lds [ i ] = 1 ; for ( let j = 0 ; j < i ; j ++ ) if ( lds [ j ] != 0 && arr [ i ] % arr [ j ] == 0 ) lds [ i ] = Math . max ( lds [ i ] , lds [ j ] + 1 ) ; } let max = Math . max ( ... lds ) ; return max ; } let arr = [ 2 , 11 , 16 , 12 , 36 , 60 , 71 , 17 , 29 , 144 , 288 , 129 , 432 , 993 ] ; let n = arr . length ; document . write ( " " + lds ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let arr = new Array ( 100 ) ; for ( let i = 0 ; i < 100 ; i ++ ) { arr [ i ] = new Array ( 100 ) ; for ( let j = 0 ; j < 100 ; j ++ ) { arr [ i ] [ j ] = new Array ( 100 ) ; for ( let k = 0 ; k < 100 ; k ++ ) { arr [ i ] [ j ] [ k ] = - 1 ; } } } function lcs ( X , Y , Z , m , n , o ) { if ( m == 0 n == 0 o == 0 ) return 0 ; if ( arr [ m - 1 ] [ n - 1 ] [ o - 1 ] != - 1 ) return arr [ m - 1 ] [ n - 1 ] [ o - 1 ] ; if ( X [ m - 1 ] == Y [ n - 1 ] && Y [ n - 1 ] == Z [ o - 1 ] ) { arr [ m - 1 ] [ n - 1 ] [ o - 1 ] = 1 + lcs ( X , Y , Z , m - 1 , n - 1 , o - 1 ) ; return arr [ m - 1 ] [ n - 1 ] [ o - 1 ] ; } else { arr [ m - 1 ] [ n - 1 ] [ o - 1 ] = max ( lcs ( X , Y , Z , m , n - 1 , o ) , max ( lcs ( X , Y , Z , m - 1 , n , o ) , lcs ( X , Y , Z , m , n , o - 1 ) ) ) ; return arr [ m - 1 ] [ n - 1 ] [ o - 1 ] ; } } function max ( a , b ) { return ( a > b ) ? a : b ; } let X = " " ; let Y = " " ; let Z = " " ; let m = X . length ; let n = Y . length ; let o = Z . length ; document . write ( " " + lcs ( X , Y , Z , m , n , o ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function numberOfWays ( x ) { let dp = Array ( x + 1 ) . fill ( 0 ) ; dp [ 0 ] = dp [ 1 ] = 1 ; for ( i = 2 ; i <= x ; i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ; return dp [ x ] ; } let x = 3 ; document . write ( numberOfWays ( x ) ) ;

Index/key variables: i, x
Accumulator variables: i
Iterator variables: i
Javascript program:
function findLongestRepeatingSubSeq ( str ) { let n = str . length ; let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i <= n ; i ++ ) { dp [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j <= n ; j ++ ) dp [ i ] [ j ] = 0 ; } for ( let i = 1 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ; } } return dp [ n ] [ n ] ; }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function waysToArrange ( N , K , k ) { let C = new Array ( N + 1 ) ; for ( let i = 0 ; i < C . length ; i ++ ) { C [ i ] = new Array ( 2 ) ; } let i , j ; for ( i = 0 ; i <= N ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) { C [ i ] [ j ] = 1 ; } else { C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ; } } } let dp = Array . from ( { length : K + 1 } , ( _ , i ) => 0 ) ; let count = 0 ; dp [ 0 ] = 1 ; for ( i = 0 ; i < K ; i ++ ) { dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ; count += k [ i ] ; } return dp [ K ] ; } let N = 4 ; let k = [ 2 , 2 ] ; let K = k . length ; document . write ( waysToArrange ( N , K , k ) ) ;

Index/key variables: K, i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
let SIZE = 100 ; function minCells ( mat , m , n ) { let dp = new Array ( m ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < m ; i ++ ) for ( let j = 0 ; j < n ; j ++ ) dp [ i ] [ j ] = Number . MAX_VALUE ; dp [ 0 ] [ 0 ] = 1 ; for ( let i = 0 ; i < m ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( dp [ i ] [ j ] != Number . MAX_VALUE && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ; if ( dp [ i ] [ j ] != Number . MAX_VALUE && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ; } } if ( dp [ m - 1 ] [ n - 1 ] != Number . MAX_VALUE ) return dp [ m - 1 ] [ n - 1 ] ; return - 1 ; } let mat = [ [ 2 , 3 , 2 , 1 , 4 ] , [ 3 , 2 , 5 , 8 , 2 ] , [ 1 , 1 , 2 , 2 , 1 ] ] ; let m = 3 , n = 5 ; document . write ( " " + " " + minCells ( mat , m , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let res = [ ] ; function GetCeilIndex ( arr , T , l , r , key ) { while ( r - l > 1 ) { let m = l + Math . floor ( ( r - l ) / 2 ) ; if ( arr [ T [ m ] ] >= key ) r = m ; else l = m ; } return r ; } function LIS ( arr , n ) { let tailIndices = new Array ( n ) ; let prevIndices = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { tailIndices [ i ] = 0 ; prevIndices [ i ] = - 1 ; } let len = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ tailIndices [ 0 ] ] ) tailIndices [ 0 ] = i ; else if ( arr [ i ] > arr [ tailIndices [ len - 1 ] ] ) { prevIndices [ i ] = tailIndices [ len - 1 ] ; tailIndices [ len ++ ] = i ; } else { let pos = GetCeilIndex ( arr , tailIndices , - 1 , len - 1 , arr [ i ] ) ; prevIndices [ i ] = tailIndices [ pos - 1 ] ; tailIndices [ pos ] = i ; } } for ( let i = tailIndices [ len - 1 ] ; i >= 0 ; i = prevIndices [ i ] ) res . push ( arr [ i ] ) ; } function longestBitonic ( arr1 , n1 , arr2 , n2 ) { LIS ( arr1 , n1 ) ; res . reverse ( ) ; arr2 . reverse ( ) ; LIS ( arr2 , n2 ) ; for ( let i = 0 ; i < res . length ; i ++ ) document . write ( res [ i ] + " " ) ; } let arr1 = [ 1 , 2 , 4 , 3 , 2 ] ; let arr2 = [ 8 , 6 , 4 , 7 , 8 , 9 ] ; let n1 = arr1 . length ; let n2 = arr2 . length ; longestBitonic ( arr1 , n1 , arr2 , n2 ) ;

Index/key variables: i, m, pos
Accumulator variables: i, len
Iterator variables: i
Javascript program:
let R = 3 ; let C = 3 ; function cal ( ones , x , y , k ) { return ones [ x + k - 1 ] [ y + k - 1 ] - ones [ x - 1 ] [ y + k - 1 ] - ones [ x + k - 1 ] [ y - 1 ] + ones [ x - 1 ] [ y - 1 ] ; } function sol ( mat ) { let ans = 0 ; let val = 0 ; let ones = new Array ( R + 1 ) ; for ( var i = 0 ; i < ones . length ; i ++ ) { ones [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < ones . length ; i ++ ) { for ( var j = 0 ; j < ones . length ; j ++ ) { ones [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= R ; i ++ ) for ( let j = 1 ; j <= C ; j ++ ) { if ( mat [ i - 1 ] [ j - 1 ] == 1 ) val = 1 ; ones [ i ] [ j ] = ones [ i - 1 ] [ j ] + ones [ i ] [ j - 1 ] - ones [ i - 1 ] [ j - 1 ] + ( val ) ; } for ( let k = 1 ; k <= Math . min ( R , C ) ; k ++ ) for ( let i = 1 ; i + k - 1 <= R ; i ++ ) for ( let j = 1 ; j + k - 1 <= C ; j ++ ) ans = Math . max ( ans , ( ones [ R ] [ C ] + k * k - 2 * cal ( ones , i , j , k ) ) ) ; return ans ; } let mat = [ [ 0 , 0 , 1 ] , [ 0 , 0 , 1 ] , [ 1 , 0 , 1 ] ] ; document . write ( sol ( mat ) ) ;

Index/key variables: C, R, i, j
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function getMinSteps ( n ) { let table = new Array ( n + 1 ) ; table . fill ( 0 ) ; table [ 1 ] = 0 ; for ( let i = 2 ; i <= n ; i ++ ) { if ( ! ( i % 2 ) && ( i % 3 ) ) table [ i ] = 1 + Math . min ( table [ i - 1 ] , table [ i / 2 ] ) ; else if ( ! ( i % 3 ) && ( i % 2 ) ) table [ i ] = 1 + Math . min ( table [ i - 1 ] , table [ i / 3 ] ) ; else if ( ! ( i % 2 ) && ! ( i % 3 ) ) table [ i ] = 1 + Math . min ( table [ i - 1 ] , Math . min ( table [ i / 2 ] , table [ i / 3 ] ) ) ; else table [ i ] = 1 + table [ i - 1 ] ; } return table [ n ] + 1 ; } let n = 10 ; document . write ( getMinSteps ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
let M = 3 ; let N = 3 ; function findMaxPoints ( A ) { let P1S = new Array ( M + 2 ) ; let P1E = new Array ( M + 2 ) ; let P2S = new Array ( M + 2 ) ; let P2E = new Array ( M + 2 ) ; for ( let i = 0 ; i < M + 2 ; i ++ ) { P1S [ i ] = new Array ( N + 2 ) ; P1E [ i ] = new Array ( N + 2 ) ; P2S [ i ] = new Array ( N + 2 ) ; P2E [ i ] = new Array ( N + 2 ) ; for ( let j = 0 ; j < N + 2 ; j ++ ) { P1S [ i ] [ j ] = 0 ; P1E [ i ] [ j ] = 0 ; P2S [ i ] [ j ] = 0 ; P2E [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= N ; i ++ ) for ( let j = 1 ; j <= M ; j ++ ) P1S [ i ] [ j ] = Math . max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ; for ( let i = N ; i >= 1 ; i -- ) for ( let j = M ; j >= 1 ; j -- ) P1E [ i ] [ j ] = Math . max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ; for ( let i = N ; i >= 1 ; i -- ) for ( let j = 1 ; j <= M ; j ++ ) P2S [ i ] [ j ] = Math . max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ; for ( let i = 1 ; i <= N ; i ++ ) for ( let j = M ; j >= 1 ; j -- ) P2E [ i ] [ j ] = Math . max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ; let ans = 0 ; for ( let i = 2 ; i < N ; i ++ ) { for ( let j = 2 ; j < M ; j ++ ) { let op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ; let op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ; ans = Math . max ( ans , Math . max ( op1 , op2 ) ) ; } } return ans ; } let A = [ [ 100 , 100 , 100 ] , [ 100 , 1 , 100 ] , [ 100 , 100 , 100 ] ] ; document . write ( " " + findMaxPoints ( A ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function longestSubseqWithDiffOne ( arr , n ) { let dp = [ ] ; for ( let i = 0 ; i < n ; i ++ ) dp [ i ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { for ( let j = 0 ; j < i ; j ++ ) { if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ; } } let result = 1 ; for ( let i = 0 ; i < n ; i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ; return result ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 3 , 2 ] ; let n = arr . length ; document . write ( longestSubseqWithDiffOne ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function catalanDP ( n ) { let catalan = [ ] catalan [ 0 ] = catalan [ 1 ] = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { catalan [ i ] = 0 ; for ( let j = 0 ; j < i ; j ++ ) catalan [ i ] += catalan [ j ] * catalan [ i - j - 1 ] ; } return catalan [ n ] ; } function countWays ( n ) { if ( n & 1 ) { document . write ( " " ) ; return 0 ; } return catalanDP ( n / 2 ) ; } document . write ( countWays ( 6 ) + " " ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var MAX = 100 ; var dp = Array ( MAX ) . fill ( - 1 ) . map ( x => Array ( MAX ) . fill ( - 1 ) . map ( x => Array ( MAX ) . fill ( - 1 ) . map ( x => Array ( 3 ) . fill ( - 1 ) ) ) ) ; function countWays ( p , q , r , last ) { if ( p < 0 q < 0 r < 0 ) return 0 ; if ( p == 1 && q == 0 && r == 0 && last == 0 ) return 1 ; if ( p == 0 && q == 1 && r == 0 && last == 1 ) return 1 ; if ( p == 0 && q == 0 && r == 1 && last == 2 ) return 1 ; if ( dp [ p ] [ q ] [ r ] [ last ] != - 1 ) return dp [ p ] [ q ] [ r ] [ last ] ; if ( last == 0 ) dp [ p ] [ q ] [ r ] [ last ] = countWays ( p - 1 , q , r , 1 ) + countWays ( p - 1 , q , r , 2 ) ; else if ( last == 1 ) dp [ p ] [ q ] [ r ] [ last ] = countWays ( p , q - 1 , r , 0 ) + countWays ( p , q - 1 , r , 2 ) ; else dp [ p ] [ q ] [ r ] [ last ] = countWays ( p , q , r - 1 , 0 ) + countWays ( p , q , r - 1 , 1 ) ; return dp [ p ] [ q ] [ r ] [ last ] ; } function countUtil ( p , q , r ) { } var p = 1 , q = 1 , r = 1 ; document . write ( countUtil ( p , q , r ) ) ;

Index/key variables: last, p, q, r
Javascript program:
function countDer ( n ) { let der = new Array ( n + 1 ) ; der [ 1 ] = 0 ; der [ 2 ] = 1 ; for ( let i = 3 ; i <= n ; ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ; return der [ n ] ; } let n = 4 ; document . write ( " " + countDer ( n ) ) ;

Index/key variables: i, n
Iterator variables: i
Javascript program:
function countSol ( coeff , n , rhs ) { let dp = new Array ( rhs + 1 ) ; dp . fill ( 0 ) ; dp [ 0 ] = 1 ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = coeff [ i ] ; j <= rhs ; j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ; return dp [ rhs ] ; } let coeff = [ 2 , 2 , 5 ] ; let rhs = 4 ; let n = coeff . length ; document . write ( countSol ( coeff , n , rhs ) ) ;

Index/key variables: i, j, rhs
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
class Node { constructor ( x ) { this . data = x ; this . left = null ; this . right = null ; } } let root ; let next = null ; function populateNext ( node ) { if ( node != null ) { populateNext ( node . right ) ; node . next = next ; next = node ; populateNext ( node . left ) ; } } root = new Node ( 10 ) root . left = new Node ( 8 ) root . right = new Node ( 12 ) root . left . left = new Node ( 3 ) p = populateNext ( root ) ptr = root . left . left while ( ptr != null ) { let print = ptr . next != null ? ptr . next . data : - 1 ; document . write ( " " + ptr . data + " " + print + " " ) ; ptr = ptr . next ; }

Class/struct names: Node
Javascript program:
function maxProd ( n ) { if ( n == 2 n == 3 ) { return ( n - 1 ) ; } let res = 1 ; while ( n > 4 ) { n -= 3 ; res *= 3 ; } return ( n * res ) ; } document . write ( " " + maxProd ( 10 ) ) ;

Accumulator variables: n, res
Javascript program:
function findWays ( m , n , x ) { let table = new Array ( n + 1 ) ; for ( let i = 0 ; i < ( n + 1 ) ; i ++ ) { table [ i ] = new Array ( x + 1 ) ; for ( let j = 0 ; j < ( x + 1 ) ; j ++ ) { table [ i ] [ j ] = 0 ; } } for ( let j = 1 ; j <= m && j <= x ; j ++ ) table [ 1 ] [ j ] = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= x ; j ++ ) { for ( let k = 1 ; k < j && k <= m ; k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ; } } return table [ n ] [ x ] ; } document . write ( findWays ( 4 , 2 , 1 ) + " " ) ; document . write ( findWays ( 2 , 2 , 3 ) + " " ) ; document . write ( findWays ( 6 , 3 , 8 ) + " " ) ; document . write ( findWays ( 4 , 2 , 5 ) + " " ) ; document . write ( findWays ( 4 , 3 , 5 ) + " " ) ;

Index/key variables: i, j, n, x
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function findWays ( f , d , s ) { let mem = new Array ( d + 1 ) ; for ( let i = 0 ; i < ( d + 1 ) ; i ++ ) { mem [ i ] = new Array ( s + 1 ) ; for ( let j = 0 ; j < s + 1 ; j ++ ) { mem [ i ] [ j ] = 0 ; } } mem [ 0 ] [ 0 ] = 1 ; for ( let i = 1 ; i <= d ; i ++ ) { for ( let j = i ; j <= s ; j ++ ) { mem [ i ] [ j ] = mem [ i ] [ j - 1 ] + mem [ i - 1 ] [ j - 1 ] ; if ( j - f - 1 >= 0 ) mem [ i ] [ j ] -= mem [ i - 1 ] [ j - f - 1 ] ; } } return mem [ d ] [ s ] ; } document . write ( findWays ( 4 , 2 , 1 ) + " " ) ; document . write ( findWays ( 2 , 2 , 3 ) + " " ) ; document . write ( findWays ( 6 , 3 , 8 ) + " " ) ; document . write ( findWays ( 4 , 2 , 5 ) + " " ) ; document . write ( findWays ( 4 , 3 , 5 ) + " " ) ;

Index/key variables: d, i, j, s
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findMinInsertions ( str , l , h ) { if ( l > h ) return Number . MAX_VALUE ; if ( l == h ) return 0 ; if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ; return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( Math . min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) } let str = " " ; document . write ( findMinInsertions ( str , 0 , str . length - 1 ) ) ;

Index/key variables: h, l
Javascript program:
function max ( x , y ) { return ( x > y ) ? x : y ; } function lps ( seq , i , j ) { if ( i == j ) { return 1 ; } if ( seq [ i ] == seq [ j ] && i + 1 == j ) { return 2 ; } if ( seq [ i ] == seq [ j ] ) { return lps ( seq , i + 1 , j - 1 ) + 2 ; } return max ( lps ( seq , i , j - 1 ) , lps ( seq , i + 1 , j ) ) ; } let seq = " " ; let n = seq . length ; document . write ( " " , lps ( seq . split ( " " ) , 0 , n - 1 ) ) ;

Index/key variables: i, j
Javascript program:
function findCount ( str1 , str2 ) { var len = str1 . length ; var len2 = str2 . length ; var ans = 21474836473 ; var hash1 = new Array ( 26 ) . fill ( 0 ) ; var hash2 = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < len ; i ++ ) hash1 [ str1 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; for ( var i = 0 ; i < len2 ; i ++ ) hash2 [ str2 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; for ( var i = 0 ; i < 26 ; i ++ ) if ( hash2 [ i ] ) ans = Math . min ( ans , hash1 [ i ] / hash2 [ i ] ) ; return ans ; } var str1 = " " ; var str2 = " " ; document . write ( findCount ( str1 , str2 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isVowel ( c ) { let vowel = " " ; for ( let i = 0 ; i < vowel . length ; ++ i ) { if ( vowel [ i ] == c ) { return true ; } } return false ; } function printRLE ( str , typed ) { let n = str . length , m = typed . length ; let j = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( str [ i ] != typed [ j ] ) { return false ; } if ( isVowel ( str [ i ] ) == false ) { j ++ ; continue ; } let count1 = 1 ; while ( i < n - 1 && str [ i ] == str [ i + 1 ] ) { count1 ++ ; i ++ ; } let count2 = 1 ; while ( j < m - 1 && typed [ j ] == str [ i ] ) { count2 ++ ; j ++ ; } if ( count1 > count2 ) { return false ; } } return true ; } let name = " " , typed = " " ; if ( printRLE ( name , typed ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: count1, count2, i, j
Iterator variables: i
Javascript program:
function censor ( text , word ) { var word_list = text . split ( " " ) ; var result = " " ; var stars = " " ; for ( var i = 0 ; i < word . length ; i ++ ) stars += " " ; var index = 0 ; for ( const i of word_list ) { if ( i === word ) word_list [ index ] = stars ; index ++ ; } for ( const i of word_list ) { result += i + " " ; } return result ; } var extract = " " + " " + " " ; var cen = " " ; document . write ( censor ( extract , cen ) + " " ) ;

Index/key variables: index
Accumulator variables: i, index, result, stars
Iterator variables: i
Javascript program:
let NO_OF_CHARS = 256 ; function getNextState ( pat , M , state , x ) { if ( state < M && x == pat [ state ] . charCodeAt ( 0 ) ) return state + 1 ; let ns , i ; for ( ns = state ; ns > 0 ; ns -- ) { if ( pat [ ns - 1 ] . charCodeAt ( 0 ) == x ) { for ( i = 0 ; i < ns - 1 ; i ++ ) if ( pat [ i ] != pat [ state - ns + 1 + i ] ) break ; if ( i == ns - 1 ) return ns ; } } return 0 ; } function computeTF ( pat , M , TF ) { let state , x ; for ( state = 0 ; state <= M ; ++ state ) for ( x = 0 ; x < NO_OF_CHARS ; ++ x ) TF [ state ] [ x ] = getNextState ( pat , M , state , x ) ; } function search ( pat , txt ) { let M = pat . length ; let N = txt . length ; let TF = new Array ( M + 1 ) ; for ( let i = 0 ; i < M + 1 ; i ++ ) { TF [ i ] = new Array ( NO_OF_CHARS ) ; for ( let j = 0 ; j < NO_OF_CHARS ; j ++ ) TF [ i ] [ j ] = 0 ; } computeTF ( pat , M , TF ) ; let i , state = 0 ; for ( i = 0 ; i < N ; i ++ ) { state = TF [ state ] [ txt [ i ] . charCodeAt ( 0 ) ] ; if ( state == M ) document . write ( " " + " " + ( i - M + 1 ) + " " ) ; } } let pat = " " . split ( " " ) ; let txt = " " . split ( " " ) ; search ( txt , pat ) ;

Index/key variables: i, j, state, x
Accumulator variables: i, j, ns
Iterator variables: i, j, ns, state, x
Javascript program:
function maxlength ( s ) { let n = s . length , i , j ; let ans = 0 ; for ( i = 0 ; i <= n - 1 ; i ++ ) { if ( s [ i ] == ' ' ) { let count = 1 ; for ( j = i + 1 ; j <= n - 1 && s [ j ] == ' ' ; j ++ ) count ++ ; ans = Math . max ( ans , count ) ; } } return ans ; } let s = " " ; document . write ( maxlength ( s ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function generateLetters ( S , P , M ) { if ( P == S . length ) { document . write ( S + " " ) ; return ; } generateLetters ( S , P + 1 , M ) ; S = S . replace ( S . charAt ( P ) , M . get ( S [ P ] ) ) generateLetters ( S , P + 1 , M ) ; return ; } let S = " " ; let M = new Map ( ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; generateLetters ( S , 0 , M ) ;

Index/key variables: P