dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function getLevenstein ( input ) { let revInput = ( input ) . split ( " " ) ; revInput = revInput . reverse ( ) ; let n = input . length ; let dp = new Array ( n + 1 ) ; for ( let i = 0 ; i < n + 1 ; i ++ ) { dp [ i ] = new Array ( n + 1 ) ; for ( let j = 0 ; j < n + 1 ; j ++ ) dp [ i ] [ j ] = 0 ; } for ( let i = 0 ; i <= n ; ++ i ) { dp [ 0 ] [ i ] = i ; dp [ i ] [ 0 ] = i ; } for ( let i = 1 ; i <= n ; ++ i ) { for ( let j = 1 ; j <= n ; ++ j ) { if ( input [ i - 1 ] == revInput [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } let res = Number . MAX_VALUE ; for ( let i = n , j = 0 ; i >= 0 ; i -- , j ++ ) { res = Math . min ( res , dp [ i ] [ j ] ) ; if ( i < n ) res = Math . min ( res , dp [ i + 1 ] [ j ] ) ; if ( i > 0 ) res = Math . min ( res , dp [ i - 1 ] [ j ] ) ; } return res ; } let input = ( " " ) ; document . write ( getLevenstein ( input ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let dp = new Array ( MAXN ) ; let nck = new Array ( MAXN ) ; for ( let i = 0 ; i < MAXN ; i ++ ) { nck [ i ] = new Array ( MAXN ) ; for ( let j = 0 ; j < MAXN ; j ++ ) nck [ i ] [ j ] = 0 ; } let log2 = new Array ( MAXN ) ; function choose ( n , k ) { if ( k > n ) { return 0 ; } if ( n <= 1 ) { return 1 ; } if ( k == 0 ) { return 1 ; } if ( nck [ n ] [ k ] != - 1 ) { return nck [ n ] [ k ] ; } let answer = choose ( n - 1 , k - 1 ) + choose ( n - 1 , k ) ; nck [ n ] [ k ] = answer ; return answer ; } function getLeft ( n ) { if ( n == 1 ) { return 0 ; } let h = log2 [ n ] ; let last = n - ( ( 1 << h ) - 1 ) ; if ( last >= ( numh / 2 ) ) { } else { return ( 1 << h ) - 1 - ( ( numh / 2 ) - last ) ; } } function numberOfHeaps ( n ) { if ( n <= 1 ) { return 1 ; } if ( dp [ n ] != - 1 ) { return dp [ n ] ; } let left = getLeft ( n ) ; let ans = ( choose ( n - 1 , left ) * numberOfHeaps ( left ) ) * ( numberOfHeaps ( n - 1 - left ) ) ; dp [ n ] = ans ; return ans ; } function solve ( n ) { for ( let i = 0 ; i <= n ; i ++ ) { dp [ i ] = - 1 ; } for ( let i = 0 ; i <= n ; i ++ ) { for ( let j = 0 ; j <= n ; j ++ ) { nck [ i ] [ j ] = - 1 ; } } let currLog2 = - 1 ; let currPower2 = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { if ( currPower2 == i ) { currLog2 ++ ; currPower2 *= 2 ; } log2 [ i ] = currLog2 ; } return numberOfHeaps ( n ) ; } let n = 10 ; document . write ( solve ( n ) ) ;

Index/key variables: i, j, k, n
Accumulator variables: currLog2, currPower2, i, j
Iterator variables: i, j
Javascript program:
var N = 5 function printHosoya ( n ) { var dp = Array . from ( Array ( N ) , ( ) => Array ( N ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1 ; for ( var i = 2 ; i < n ; i ++ ) { for ( var j = 0 ; j < n ; j ++ ) { if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ; else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ; } } for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) document . write ( dp [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } var n = 5 ; printHosoya ( n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function numberofways ( n , m ) { let dp = new Array ( n + 2 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( n + 2 ) ; for ( let j = 0 ; j < dp [ i ] . length ; j ++ ) { dp [ i ] [ j ] = 0 ; } } dp [ 0 ] [ n + 1 ] = 1 ; for ( let k = n ; k >= m ; k -- ) { for ( let i = 0 ; i <= n ; i ++ ) { dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ; if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ; } } return dp [ n ] [ m ] ; } let n = 3 , m = 1 ; document . write ( numberofways ( n , m ) ) ;

Index/key variables: i, j, k, m, n
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function eulerian ( n , m ) { var dp = Array . from ( Array ( n + 1 ) , ( ) => Array ( m + 1 ) . fill ( 0 ) ) ; for ( var i = 1 ; i <= n ; i ++ ) { for ( var j = 0 ; j <= m ; j ++ ) { if ( i > j ) { if ( j == 0 ) dp [ i ] [ j ] = 1 ; else dp [ i ] [ j ] = ( ( i - j ) * dp [ i - 1 ] [ j - 1 ] ) + ( ( j + 1 ) * dp [ i - 1 ] [ j ] ) ; } } } return dp [ n ] [ m ] ; } var n = 3 , m = 1 ; document . write ( eulerian ( n , m ) ) ;

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function dealnnoy ( n , m ) { var dp = Array . from ( Array ( m + 1 ) , ( ) => Array ( n + 1 ) ) ; for ( var i = 0 ; i <= m ; i ++ ) dp [ i ] [ 0 ] = 1 ; for ( var i = 0 ; i <= m ; i ++ ) dp [ 0 ] [ i ] = 1 ; for ( var i = 1 ; i <= m ; i ++ ) for ( var j = 1 ; j <= n ; j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ; return dp [ m ] [ n ] ; } var n = 3 , m = 4 ; document . write ( dealnnoy ( n , m ) ) ;

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

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxDP ( n ) { let res = [ ] ; res [ 0 ] = 0 ; res [ 1 ] = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { res [ i ] = Math . max ( i , ( res [ Math . floor ( i / 2 ) ] + res [ Math . floor ( i / 3 ) ] + res [ Math . floor ( i / 4 ) ] + res [ Math . floor ( i / 5 ) ] ) ) ; } return res [ n ] ; } let n = 60 ; document . write ( " " + maxDP ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
var MAX = 100 ; function allones ( s , n ) { var co = 0 ; for ( var i = 0 ; i < s . length ; i ++ ) co += ( s [ i ] == ' ' ) ; return ( co == n ) ; } function findlength ( arr , s , n , ind , st , dp ) { if ( ind >= n ) return 0 ; if ( dp [ ind ] [ st ] != - 1 ) return dp [ ind ] [ st ] ; if ( st == 0 ) return dp [ ind ] [ st ] = Math . max ( arr [ ind ] + findlength ( arr , s , n , ind + 1 , 1 , dp ) , findlength ( arr , s , n , ind + 1 , 0 , dp ) ) ; else return dp [ ind ] [ st ] = Math . max ( arr [ ind ] + findlength ( arr , s , n , ind + 1 , 1 , dp ) , 0 ) ; } function maxLen ( s , n ) { if ( allones ( s , n ) ) return - 1 ; var arr = Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) arr [ i ] = ( s [ i ] == ' ' ? 1 : - 1 ) ; var dp = Array . from ( Array ( MAX ) , ( ) => Array ( 3 ) . fill ( - 1 ) ) ; return findlength ( arr , s , n , 0 , 0 , dp ) ; } var s = " " ; var n = 11 ; document . write ( maxLen ( s , n ) ) ;

Index/key variables: i, ind, st
Accumulator variables: co, i
Iterator variables: i
Javascript program:
R = 4 C = 3 function isSafe ( x , y ) { return ( x < R && y < C ) ; } function minJump ( height , x , y ) { if ( x == R - 1 && y == C - 1 ) return 0 ; var diag = 1000000000 ; if ( isSafe ( x + 1 , y + 1 ) ) diag = minJump ( height , x + 1 , y + 1 ) + Math . abs ( height [ x ] [ y ] - height [ x + 1 ] [ y + 1 ] ) ; var down = 1000000000 ; if ( isSafe ( x + 1 , y ) ) down = minJump ( height , x + 1 , y ) + Math . abs ( height [ x ] [ y ] - height [ x + 1 ] [ y ] ) ; var right = 1000000000 ; if ( isSafe ( x , y + 1 ) ) right = minJump ( height , x , y + 1 ) + Math . abs ( height [ x ] [ y ] - height [ x ] [ y + 1 ] ) ; return Math . min ( down , Math . min ( right , diag ) ) ; } var height = [ [ 5 , 4 , 2 ] , [ 9 , 2 , 1 ] , [ 2 , 5 , 9 ] , [ 1 , 3 , 11 ] ] ; document . write ( minJump ( height , 0 , 0 ) ) ;

Index/key variables: x, y
Javascript program:
function maxLength ( s , n ) { let invalidOpenBraces = 0 ; let invalidCloseBraces = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ' ) { invalidOpenBraces ++ ; } else { if ( invalidOpenBraces == 0 ) { invalidCloseBraces ++ ; } else { invalidOpenBraces -- ; } } } return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ; } let s = " " ; let n = s . length ; document . write ( maxLength ( s , n ) ) ;

Index/key variables: i
Accumulator variables: i, invalidCloseBraces, invalidOpenBraces
Iterator variables: i
Javascript program:
function alternateSubarray ( arr , n ) { let len = new Array ( n ) ; len [ n - 1 ] = 1 ; for ( let i = n - 2 ; i >= 0 ; -- i ) { if ( arr [ i ] ^ arr [ i + 1 ] == 1 ) len [ i ] = len [ i + 1 ] + 1 ; else len [ i ] = 1 ; } for ( let i = 0 ; i < n ; ++ i ) document . write ( len [ i ] + " " ) ; } let arr = [ 1 , 0 , 1 , 0 , 0 , 1 ] ; let n = arr . length ; alternateSubarray ( arr , n ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function alternateSubarray ( arr , n ) { let count = 1 ; let prev = arr [ 0 ] ; for ( let i = 1 ; i < n ; ++ i ) { if ( ( arr [ i ] ^ prev ) == false ) { while ( count > 0 ) { document . write ( count -- + " " ) ; } } ++ count ; prev = arr [ i ] ; } while ( count != 0 ) { document . write ( count -- + " " ) ; } } let arr = [ true , false , true , false , false , true ] ; let n = arr . length ; alternateSubarray ( arr , n ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Javascript program:
let MAX = 10 ; function lcs ( dp , arr1 , n , arr2 , m , k ) { if ( k < 0 ) return - 10000000 ; if ( n < 0 m < 0 ) return 0 ; let ans = dp ; if ( ans != - 1 ) return ans ; try { ans = Math . max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ; if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ; ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ; } catch ( e ) { } return ans ; } let k = 0 ; let arr1 = [ 1 , 2 , 3 , 4 , 5 ] ; let arr2 = [ 5 , 3 , 1 , 4 , 2 ] ; let n = arr1 . length ; let m = arr2 . length ; let dp = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) for ( let j = 0 ; j < MAX ; j ++ ) for ( let l = 0 ; l < MAX ; l ++ ) dp = - 1 ; document . write ( lcs ( dp , arr1 , n , arr2 , m , k ) ) ;

Accumulator variables: i, j, l
Iterator variables: i, j, l
Javascript program:
function countWays ( n ) { let dp = new Array ( 2 ) ; for ( let i = 0 ; i < 2 ; i ++ ) { dp [ i ] = new Array ( n + 1 ) ; } dp [ 0 ] [ 1 ] = 1 ; dp [ 1 ] [ 1 ] = 2 ; for ( let i = 2 ; i <= n ; i ++ ) { dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ; dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ; } return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ; } let n = 5 ; document . write ( " " + n + " " + countWays ( n ) ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function countways ( n ) { let A = new Array ( n + 1 ) . fill ( 0 ) ; A [ 0 ] = 1 ; A [ 1 ] = 3 ; A [ 2 ] = 7 ; for ( let i = 2 ; i <= n ; i ++ ) { A [ i ] = 2 * A [ i - 1 ] + A [ i - 2 ] ; } return A [ n ] ; } let n = 5 ; document . write ( countways ( 5 ) )

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxLenSub ( arr , n ) { let mls = new Array ( n ) . fill ( 1 ) , max = 0 ; for ( let i = 0 ; i < n ; i ++ ) mls [ i ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) for ( let j = 0 ; j < i ; j ++ ) if ( Math . abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ; for ( let i = 0 ; i < n ; i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ; return max ; } let arr = [ 2 , 5 , 6 , 3 , 7 , 6 , 5 , 8 ] ; let n = arr . length ; document . write ( " " + maxLenSub ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findWinner ( x , y , n ) { var dp = Array ( n + 1 ) . fill ( 0 ) ; dp [ 0 ] = false ; dp [ 1 ] = true ; for ( var i = 2 ; i <= n ; i ++ ) { if ( i - 1 >= 0 && ! dp [ i - 1 ] ) dp [ i ] = true ; else if ( i - x >= 0 && ! dp [ i - x ] ) dp [ i ] = true ; else if ( i - y >= 0 && ! dp [ i - y ] ) dp [ i ] = true ; else dp [ i ] = false ; } return dp [ n ] ; } var x = 3 , y = 4 , n = 5 ; if ( findWinner ( x , y , n ) ) document . write ( ' ' ) ; else document . write ( ' ' ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxGameByWinner ( N ) { let dp = new Array ( N ) . fill ( 0 ) ; dp [ 0 ] = 1 ; dp [ 1 ] = 2 ; let i = 2 ; do { dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ; } while ( dp [ i ++ ] <= N ) ; return ( i - 2 ) ; } let N = 10 ; document . write ( maxGameByWinner ( N ) ) ;

Index/key variables: i
Accumulator variables: i
Javascript program:
function minRemove ( arr , n ) { let LIS = new Array ( n ) . fill ( 0 ) ; let len = 0 ; for ( let i = 0 ; i < n ; i ++ ) LIS [ i ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { for ( let j = 0 ; j < i ; j ++ ) { if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) LIS [ i ] = Math . max ( LIS [ i ] , LIS [ j ] + 1 ) ; } len = Math . max ( len , LIS [ i ] ) ; } return n - len ; } let arr = [ 1 , 2 , 6 , 5 , 4 ] ; let n = arr . length ; document . write ( minRemove ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countTransformation ( a , b ) { var n = a . length , m = b . length ; if ( m == 0 ) { return 1 ; } var dp = new Array ( m , n ) ; for ( var i = 0 ; i < m ; i ++ ) { for ( var j = i ; j < n ; j ++ ) { if ( i == 1 ) { if ( j == 1 ) { dp [ i , j ] = ( a [ j ] == b [ i ] ) ? 1 : 0 ; } else if ( a [ j ] == b [ i ] ) { dp [ i , j ] = dp [ i , j - 1 ] + 1 ; } else { dp [ i , j ] = dp [ i , j - 1 ] ; } } else if ( a [ j ] == b [ j ] ) { dp [ i , j ] = dp [ i , j - 1 ] + dp [ i - 1 , j - 1 ] ; } else { dp [ i , j ] = dp [ i , j - 1 ] ; } } } return dp [ m - 1 , n - 1 ] ; } var a = " " , b = " " ; document . write ( countTransformation ( a , b ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
var max = 100000 ; function baseconversion ( arr , num , base ) { var i = 0 , rem , j ; if ( num == 0 ) { return 0 ; } while ( num > 0 ) { rem = num % base ; arr [ i ++ ] = rem ; num = parseInt ( num / base ) ; } return i ; } var arr = Array ( max ) . fill ( 0 ) ; var n = 10 ; var size = baseconversion ( arr , n - 1 , 6 ) ; if ( size == 0 ) document . write ( size ) ; for ( i = size - 1 ; i >= 0 ; i -- ) { document . write ( arr [ i ] ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
var MAX = 1000 ; function maxSubsequenceSubstring ( x , y , n , m ) { var dp = Array . from ( Array ( MAX ) , ( ) => Array ( MAX ) ) ; for ( var i = 0 ; i <= m ; i ++ ) for ( var j = 0 ; j <= n ; j ++ ) dp [ i ] [ j ] = 0 ; for ( var i = 1 ; i <= m ; i ++ ) { for ( var j = 1 ; j <= n ; j ++ ) { if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ; } } var ans = 0 ; for ( var i = 1 ; i <= m ; i ++ ) ans = Math . max ( ans , dp [ i ] [ n ] ) ; return ans ; } var x = " " ; var y = " " ; var n = x . length , m = y . length ; document . write ( maxSubsequenceSubstring ( x , y , n , m ) ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minPyramidCost ( arr , N ) { let left = new Array ( N ) ; let right = new Array ( N ) ; left [ 0 ] = Math . min ( arr [ 0 ] , 1 ) ; for ( let i = 1 ; i < N ; ++ i ) left [ i ] = Math . min ( arr [ i ] , Math . min ( left [ i - 1 ] + 1 , i + 1 ) ) ; right [ N - 1 ] = Math . min ( arr [ N - 1 ] , 1 ) ; for ( let i = N - 2 ; i >= 0 ; -- i ) right [ i ] = Math . min ( arr [ i ] , Math . min ( right [ i + 1 ] + 1 , N - i ) ) ; let tot = new Array ( N ) ; for ( let i = 0 ; i < N ; ++ i ) tot [ i ] = Math . min ( right [ i ] , left [ i ] ) ; let max_ind = 0 ; for ( let i = 0 ; i < N ; ++ i ) if ( tot [ i ] > tot [ max_ind ] ) max_ind = i ; let cost = 0 ; let height = tot [ max_ind ] ; for ( let x = max_ind ; x >= 0 ; -- x ) { cost += arr [ x ] - height ; if ( height > 0 ) -- height ; } height = tot [ max_ind ] - 1 ; for ( let x = max_ind + 1 ; x < N ; ++ x ) { cost += arr [ x ] - height ; if ( height > 0 ) -- height ; } return cost ; } let arr = [ 1 , 2 , 3 , 4 , 2 , 1 ] ; let N = arr . length ; document . write ( minPyramidCost ( arr , N ) ) ;

Index/key variables: i, max_ind, x
Accumulator variables: cost
Iterator variables: i, x
Javascript program:
function maxSum ( grid , n ) { let incl = Math . max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ; let excl = 0 , excl_new ; for ( let i = 1 ; i < n ; i ++ ) { excl_new = Math . max ( excl , incl ) ; incl = excl + Math . max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ; excl = excl_new ; } return Math . max ( excl , incl ) ; } let grid = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 6 , 7 , 8 , 9 , 10 ] ] ; let n = 5 ; document . write ( maxSum ( grid , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minInsertionStepToSortArray ( arr , N ) { let lis = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) { lis [ i ] = 1 ; } for ( let i = 1 ; i < N ; i ++ ) { for ( let j = 0 ; j < i ; j ++ ) { if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) { lis [ i ] = lis [ j ] + 1 ; } } } let max = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( max < lis [ i ] ) { max = lis [ i ] ; } } return ( N - max ) ; } let arr = new Array ( 2 , 3 , 5 , 1 , 4 , 7 , 6 ) ; let N = arr . length ; document . write ( minInsertionStepToSortArray ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let NO_OF_CHARS = 256 ; function printDistinct ( str ) { let count = new Array ( NO_OF_CHARS ) ; for ( let i = 0 ; i < NO_OF_CHARS ; i ++ ) { count [ i ] = 0 ; } let i ; for ( i = 0 ; i < str . length ; i ++ ) if ( str [ i ] != ' ' ) count [ str [ i ] . charCodeAt ( 0 ) ] ++ ; let n = i ; for ( i = 0 ; i < n ; i ++ ) if ( count [ str [ i ] . charCodeAt ( 0 ) ] == 1 ) document . write ( str [ i ] ) ; } let str = " " ; printDistinct ( str ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countWaysToJump ( arr , n ) { let count_jump = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { count_jump [ i ] = 0 ; } for ( let i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ; for ( let j = i + 1 ; j < n - 1 && j <= arr [ i ] + i ; j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ; if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ; } for ( let i = 0 ; i < n ; i ++ ) document . write ( count_jump [ i ] + " " ) ; } let arr = [ 1 , 3 , 5 , 8 , 9 , 1 , 0 , 7 , 6 , 8 , 9 ] ; let n = arr . length ; countWaysToJump ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minStepToDeleteString ( 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 len = 1 ; len <= N ; len ++ ) { for ( let i = 0 , j = len - 1 ; j < N ; i ++ , j ++ ) { if ( len == 1 ) dp [ i ] [ j ] = 1 ; else { dp [ i ] [ j ] = 1 + dp [ i + 1 ] [ j ] ; if ( str [ i ] == str [ i + 1 ] ) dp [ i ] [ j ] = Math . min ( 1 + dp [ i + 2 ] [ j ] , dp [ i ] [ j ] ) ; for ( let K = i + 2 ; K <= j ; K ++ ) if ( str [ i ] == str [ K ] ) dp [ i ] [ j ] = Math . min ( dp [ i + 1 ] [ K - 1 ] + dp [ K + 1 ] [ j ] , dp [ i ] [ j ] ) ; } } } return dp [ 0 ] [ N - 1 ] ; } let str = " " ; document . write ( minStepToDeleteString ( str ) ) ;

Index/key variables: K, i, j
Accumulator variables: K, i, j, len
Iterator variables: K, i, j, len
Javascript program:
let inf = 1000000000 ; let ans = inf ; function solve ( i , par , a , n , k , current_ans ) { if ( par > k ) return ; if ( par == k && i == n - 1 ) { ans = Math . min ( ans , current_ans ) ; return ; } for ( let j = i + 1 ; j < n ; j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ; } let k = 2 ; let a = [ 1 , 5 , 8 , 10 ] ; let n = a . length ; solve ( - 1 , 0 , a , n , k , 0 ) ; document . write ( ans ) ;

Index/key variables: j
Accumulator variables: j
Iterator variables: j
Javascript program:
let MAX = 1000 ; function numofArray ( n , m ) { let dp = new Array ( MAX ) ; let di = new Array ( MAX ) ; let mu = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { dp [ i ] = new Array ( MAX ) ; for ( let j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( let i = 0 ; i < MAX ; i ++ ) { di [ i ] = [ ] ; mu [ i ] = [ ] ; } for ( let i = 1 ; i <= m ; i ++ ) { for ( let j = 2 * i ; j <= m ; j += i ) { di [ j ] . push ( i ) ; mu [ i ] . push ( j ) ; } di [ i ] . push ( i ) ; } for ( let i = 1 ; i <= m ; i ++ ) dp [ 1 ] [ i ] = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { for ( let j = 1 ; j <= m ; j ++ ) { dp [ i ] [ j ] = 0 ; for ( let x = 0 ; x < di [ j ] . length ; x ++ ) dp [ i ] [ j ] += dp [ i - 1 ] [ di [ j ] [ x ] ] ; for ( let x = 0 ; x < mu [ j ] . length ; x ++ ) dp [ i ] [ j ] += dp [ i - 1 ] [ mu [ j ] [ x ] ] ; } } let ans = 0 ; for ( let i = 1 ; i <= m ; i ++ ) { ans += dp [ n ] [ i ] ; di [ i ] = [ ] ; mu [ i ] = [ ] ; } return ans ; } let n = 3 , m = 3 ; document . write ( numofArray ( n , m ) ) ;

Index/key variables: i, j, n, x
Accumulator variables: ans, i, j, x
Iterator variables: i, j, x
Javascript program:
function stringReduction ( str ) { var n = str . length ; var count = Array . from ( { length : 3 } , ( _ , i ) => 0 ) ; for ( var i = 0 ; i < n ; ++ i ) { count [ str . charAt ( i ) . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } if ( count [ 0 ] == n count [ 1 ] == n count [ 2 ] == n ) { return n ; } if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) { return 2 ; } return 1 ; } var str = " " ; document . write ( stringReduction ( str ) ) ;

Iterator variables: i
Javascript program:
let MAX = 100 ; let dp = new Array ( MAX ) ; function largestZigZagSumRec ( mat , i , j , n ) { if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ; if ( i == n - 1 ) return ( dp [ i ] [ j ] = mat [ i ] [ j ] ) ; let zzs = 0 ; for ( let k = 0 ; k < n ; k ++ ) if ( k != j ) zzs = Math . max ( zzs , largestZigZagSumRec ( mat , i + 1 , k , n ) ) ; return ( dp [ i ] [ j ] = ( zzs + mat [ i ] [ j ] ) ) ; } function largestZigZag ( mat , n ) { for ( let i = 0 ; i < MAX ; i ++ ) { dp [ i ] = new Array ( MAX ) ; for ( let k = 0 ; k < MAX ; k ++ ) dp [ i ] [ k ] = - 1 ; } let res = 0 ; for ( let j = 0 ; j < n ; j ++ ) res = Math . max ( res , largestZigZagSumRec ( mat , 0 , j , n ) ) ; return res ; } let n = 3 ; let mat = [ [ 4 , 2 , 1 ] , [ 3 , 9 , 6 ] , [ 11 , 3 , 15 ] ] ; document . write ( " " + largestZigZag ( mat , n ) ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function countSubsequences ( s ) { let aCount = 0 ; let bCount = 0 ; let cCount = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == ' ' ) aCount = ( 1 + 2 * aCount ) ; else if ( s [ i ] == ' ' ) bCount = ( aCount + 2 * bCount ) ; else if ( s [ i ] == ' ' ) cCount = ( bCount + 2 * cCount ) ; } return cCount ; } let s = " " ; document . write ( countSubsequences ( s ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxRevenue ( m , x , revenue , n , t ) { let maxRev = new Array ( m + 1 ) ; for ( let i = 0 ; i < m + 1 ; i ++ ) maxRev [ i ] = 0 ; let nxtbb = 0 ; for ( let i = 1 ; i <= m ; i ++ ) { if ( nxtbb < n ) { if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ; else { if ( i <= t ) maxRev [ i ] = Math . max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ; else maxRev [ i ] = Math . max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ; nxtbb ++ ; } } else maxRev [ i ] = maxRev [ i - 1 ] ; } return maxRev [ m ] ; } let m = 20 ; let x = [ 6 , 7 , 12 , 13 , 14 ] ; let revenue = [ 5 , 6 , 5 , 3 , 1 ] ; let n = x . length ; let t = 5 ; document . write ( maxRevenue ( m , x , revenue , n , t ) ) ;

Index/key variables: i, m, nxtbb
Accumulator variables: i, nxtbb
Iterator variables: i