dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function alternatingSum ( arr ) { var sum = 0 ; var sumSoFar = 0 ; for ( var i = 0 ; i < arr . length ; i ++ ) { if ( i % 2 == 1 ) { sumSoFar -= arr [ i ] ; } else { sumSoFar = Math . max ( sumSoFar + arr [ i ] , arr [ i ] ) ; } sum = Math . max ( sum , sumSoFar ) ; } sumSoFar = 0 ; for ( var i = 1 ; i < arr . length ; i ++ ) { if ( i % 2 == 0 ) { sumSoFar -= arr [ i ] ; } else { sumSoFar = Math . max ( sumSoFar + arr [ i ] , arr [ i ] ) ; } sum = Math . max ( sum , sumSoFar ) ; } return sum ; } var arr = new Array ( - 4 , - 10 , 3 , 5 ) ; var ans = alternatingSum ( arr ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: i, sumSoFar
Iterator variables: i
Javascript program:
function smallestSubWithSum ( arr , n , x ) { let min_len = n + 1 ; for ( let start = 0 ; start < n ; start ++ ) { let curr_sum = arr [ start ] ; if ( curr_sum > x ) return 1 ; for ( let end = start + 1 ; end < n ; end ++ ) { curr_sum += arr [ end ] ; if ( curr_sum > x && ( end - start + 1 ) < min_len ) min_len = ( end - start + 1 ) ; } } return min_len ; } let arr1 = [ 1 , 4 , 45 , 6 , 10 , 19 ] ; let x = 51 ; let n1 = arr1 . length ; let res1 = smallestSubWithSum ( arr1 , n1 , x ) ; ( res1 == n1 + 1 ) ? document . write ( " " ) : document . write ( res1 + " " ) ; let arr2 = [ 1 , 10 , 5 , 2 , 7 ] ; let n2 = arr2 . length ; x = 9 ; let res2 = smallestSubWithSum ( arr2 , n2 , x ) ; ( res2 == n2 + 1 ) ? document . write ( " " ) : document . write ( res2 + " " ) ; let arr3 = [ 1 , 11 , 100 , 1 , 0 , 200 , 3 , 2 , 1 , 250 ] ; let n3 = arr3 . length ; x = 280 ; let res3 = smallestSubWithSum ( arr3 , n3 , x ) ; ( res3 == n3 + 1 ) ? document . write ( " " ) : document . write ( res3 + " " ) ;

Index/key variables: end, start
Accumulator variables: curr_sum, end, start
Iterator variables: end, start
Javascript program:
function smallestSubWithSum ( arr , n , x ) { let curr_sum = 0 , min_len = n + 1 ; let start = 0 , end = 0 ; while ( end < n ) { while ( curr_sum <= x && end < n ) curr_sum += arr [ end ++ ] ; while ( curr_sum > x && start < n ) { if ( end - start < min_len ) min_len = end - start ; curr_sum -= arr [ start ++ ] ; } } return min_len ; } let arr1 = [ 1 , 4 , 45 , 6 , 10 , 19 ] ; let x = 51 ; let n1 = arr1 . length ; let res1 = smallestSubWithSum ( arr1 , n1 , x ) ; ( res1 == n1 + 1 ) ? document . write ( " " ) : document . write ( res1 + " " ) ; let arr2 = [ 1 , 10 , 5 , 2 , 7 ] ; let n2 = arr2 . length ; x = 9 ; let res2 = smallestSubWithSum ( arr2 , n2 , x ) ; ( res2 == n2 + 1 ) ? document . write ( " " ) : document . write ( res2 + " " ) ; let arr3 = [ 1 , 11 , 100 , 1 , 0 , 200 , 3 , 2 , 1 , 250 ] ; let n3 = arr3 . length ; x = 280 ; let res3 = smallestSubWithSum ( arr3 , n3 , x ) ; ( res3 == n3 + 1 ) ? document . write ( " " ) : document . write ( res3 + " " ) ;

Accumulator variables: curr_sum, end, start
Javascript program:
function numberOfArrays ( n , l ) { let dp = Array ( l + 1 ) . fill ( ) . map ( ( ) => Array ( n + 1 ) . fill ( 0 ) ) ; dp [ 0 ] [ 1 ] = 1 ; for ( let i = 0 ; i < l ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { for ( let k = j ; k <= n ; k += j ) { dp [ i + 1 ] [ k ] += dp [ i ] [ j ] ; } } } let ans = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { ans += dp [ l ] [ i ] ; } return ans ; } let N = 2 , L = 4 ; document . write ( numberOfArrays ( N , L ) ) ;

Index/key variables: i, j, k, l
Accumulator variables: ans, i, j, k
Iterator variables: i, j, k
Javascript program:
let arr = [ 16 , 16 , 16 ] ; function countMinOperations ( n ) { let result = 0 ; while ( true ) { let zero_count = 0 ; let i ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 1 ) break ; else if ( arr [ i ] == 0 ) zero_count ++ ; } if ( zero_count == n ) return result ; if ( i == n ) { for ( let j = 0 ; j < n ; j ++ ) arr [ j ] = arr [ j ] / 2 ; result ++ ; } for ( let j = i ; j < n ; j ++ ) { if ( arr [ j ] % 2 == 1 ) { arr [ j ] -- ; result ++ ; } } } } document . write ( " " + " " + " " + countMinOperations ( arr . length ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, result, zero_count
Iterator variables: i, j
Javascript program:
function recursiveChoosing ( arr , start , M , dp ) { let key = [ start , M ] ; if ( start >= N ) { return 0 ; } if ( N - start <= 2 * M ) { let sum = 0 ; for ( let i = start ; i < arr . length ; i ++ ) { sum = sum + arr [ i ] ; } return sum ; } let psa = 0 ; let sum = 0 ; for ( let i = start ; i < arr . length ; i ++ ) { sum = sum + arr [ i ] ; } let total = sum ; if ( dp . has ( key ) ) { return dp [ key ] ; } for ( let x = 1 ; x < 2 * M + 1 ; x ++ ) { let psb = recursiveChoosing ( arr , start + x , Math . max ( x , M ) , dp ) psa = Math . max ( psa , total - psb ) ; } dp [ key ] = psa ; return dp [ key ] ; } let arr = [ 2 , 7 , 9 , 4 , 4 ] ; let N = arr . length ; let dp = new Map ( ) ; document . write ( recursiveChoosing ( arr , 0 , 1 , dp ) )

Index/key variables: i, key
Accumulator variables: i, x
Iterator variables: i, x
Javascript program:
let dp = new Array ( 100 ) . fill ( 0 ) . map ( ( ) => new Array ( 3 ) . fill ( - 1 ) ) ; function maxSum ( arr , i , n , prev , is_selected ) { if ( i == n ) { return 0 ; } let cur = Math . abs ( arr [ i ] ) % 2 ; if ( dp [ i ] [ prev ] != - 1 ) { return dp [ i ] [ prev ] ; } if ( i == n - 1 && is_selected == 0 ) return dp [ i ] [ prev ] = arr [ i ] ; if ( cur != prev ) { dp [ i ] [ prev ] = arr [ i ] + maxSum ( arr , i + 1 , n , cur , 1 ) ; } dp [ i ] [ prev ] = Math . max ( dp [ i ] [ prev ] , maxSum ( arr , i + 1 , n , prev , is_selected ) ) ; return dp [ i ] [ prev ] ; } function maxSumUtil ( arr , n ) { document . write ( maxSum ( arr , 0 , n , 2 , 0 ) ) ; } let arr = [ 1 , 2 , 6 , 8 , - 5 , 10 ] ; let N = arr . length maxSumUtil ( arr , N ) ;

Index/key variables: i, prev
Javascript program:
function findMinOps ( arr , n ) { let ans = 0 ; for ( let i = 0 , j = n - 1 ; i <= j ; ) { if ( arr [ i ] == arr [ j ] ) { i ++ ; j -- ; } else if ( arr [ i ] > arr [ j ] ) { j -- ; arr [ j ] += arr [ j + 1 ] ; ans ++ ; } else { i ++ ; arr [ i ] += arr [ i - 1 ] ; ans ++ ; } } return ans ; } let arr = [ 1 , 4 , 5 , 9 , 1 ] ; document . write ( " " + findMinOps ( arr , arr . length ) ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i
Javascript program:
function findSmallest ( arr , n ) { var res = 1 ; for ( i = 0 ; i < n && arr [ i ] <= res ; i ++ ) res = res + arr [ i ] ; return res ; } var arr1 = [ 1 , 3 , 4 , 5 ] ; var n1 = arr1 . length ; document . write ( findSmallest ( arr1 , n1 ) + " " ) ; var arr2 = [ 1 , 2 , 6 , 10 , 11 , 15 ] ; var n2 = arr2 . length ; document . write ( findSmallest ( arr2 , n2 ) + " " ) ; var arr3 = [ 1 , 1 , 1 , 1 ] ; var n3 = arr3 . length ; document . write ( findSmallest ( arr3 , n3 ) + " " ) ; var arr4 = [ 1 , 1 , 3 , 4 ] ; var n4 = arr4 . length ; document . write ( findSmallest ( arr4 , n4 ) + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let s ; function countXOR ( arr , comb , start , end , index , r ) { if ( index == r ) { let new_xor = 0 ; for ( let j = 0 ; j < r ; j ++ ) { new_xor ^= comb [ j ] ; } s . add ( new_xor ) ; return ; } for ( let i = start ; i <= end && end - i + 1 >= r - index ; i ++ ) { comb [ index ] = arr [ i ] ; countXOR ( arr , comb , i + 1 , end , index + 1 , r ) ; } } function maxSizeSet ( arr , N ) { for ( let r = 1 ; r <= N ; r ++ ) { let comb = new Array ( r + 1 ) ; countXOR ( arr , comb , 0 , N - 1 , 0 , r ) ; } document . write ( s . size ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; s = new Set ( ) ; maxSizeSet ( arr , N ) ;

Index/key variables: i, index, j
Accumulator variables: i, j, new_xor, r
Iterator variables: i, j, r
Javascript program:
function maxSubArraySum ( a , size ) { let max_so_far = Number . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ; for ( let i = 0 ; i < size ; i ++ ) { max_ending_here += a [ i ] ; if ( max_so_far < max_ending_here ) { max_so_far = max_ending_here ; start = s ; end = i ; } if ( max_ending_here < 0 ) { max_ending_here = 0 ; s = i + 1 ; } } return ( end - start + 1 ) ; } let a = [ - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 ] ; let n = a . length ; document . write ( maxSubArraySum ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, max_ending_here
Iterator variables: i
Javascript program:
function LongSubarrSeq ( arr1 , arr2 ) { let M = arr1 . length ; let N = arr2 . length ; let maxL = 0 ; let DP = new Array ( M + 1 ) ; for ( var i = 0 ; i < DP . length ; i ++ ) { DP [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < DP . length ; i ++ ) { for ( var j = 0 ; j < DP . length ; j ++ ) { DP [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= M ; i ++ ) { for ( let j = 1 ; j <= N ; j ++ ) { if ( arr1 [ i - 1 ] == arr2 [ j - 1 ] ) { DP [ i ] [ j ] = 1 + DP [ i - 1 ] [ j - 1 ] ; } else { DP [ i ] [ j ] = DP [ i ] [ j - 1 ] ; } } } for ( let i = 1 ; i <= M ; i ++ ) { for ( let j = 1 ; j <= N ; j ++ ) { maxL = Math . max ( maxL , DP [ i ] [ j ] ) ; } } return maxL ; } let arr1 = [ 4 , 2 , 3 , 1 , 5 , 6 ] ; let arr2 = [ 3 , 1 , 4 , 6 , 5 , 2 ] ; document . write ( LongSubarrSeq ( arr1 , arr2 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findMinDiff ( arr , n ) { let diff = Number . MAX_VALUE ; for ( let i = 0 ; i < n - 1 ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ; return diff ; } let arr = [ 1 , 5 , 3 , 19 , 18 , 25 ] ; document . write ( " " + findMinDiff ( arr , arr . length ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findLongestSubstring ( posA , posB , A , B , canSkip , n , dp ) { if ( posA >= n posB >= n ) { return 0 ; } if ( dp [ posA ] [ posB ] [ canSkip ] != - 1 ) { return dp [ posA ] [ posB ] [ canSkip ] ; } var op1 = 0 ; var op2 = 0 ; var op3 = 0 ; if ( A [ posA ] == B [ posB ] ) { op1 = 1 + findLongestSubstring ( posA + 1 , posB + 1 , A , B , 0 , n , dp ) ; } if ( canSkip ) { op2 = findLongestSubstring ( posA + 1 , posB , A , B , canSkip , n , dp ) ; } op3 = findLongestSubstring ( posA , posB + 1 , A , B , canSkip , n , dp ) ; return dp [ posA ] [ posB ] [ canSkip ] = Math . max ( op1 , Math . max ( op2 , op3 ) ) ; } function minOperations ( A , B , N ) { var dp = Array . from ( Array ( N ) , ( ) => Array ( N ) ) ; for ( var i = 0 ; i < N ; i ++ ) for ( var j = 0 ; j < N ; j ++ ) dp [ i ] [ j ] = new Array ( 2 ) . fill ( - 1 ) ; document . write ( N - findLongestSubstring ( 0 , 0 , A , B , 1 , N , dp ) ) ; } var A = " " ; var B = " " ; var N = A . length ; minOperations ( A , B , N ) ;

Index/key variables: canSkip, i, j, posA, posB
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MOD = 1000000007 ; let dp = new Array ( 5005 ) ; for ( let i = 0 ; i < 12 ; i ++ ) { dp [ i ] = new Array ( 12 ) ; for ( let j = 0 ; j < 12 ; j ++ ) { dp [ i ] [ j ] = new Array ( 12 ) ; for ( let k = 0 ; k < 12 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } function findCountUtil ( N , maxDigit , position , previous , count ) { if ( position == N ) { return 1 ; } let ans = dp [ position ] [ previous ] [ count ] ; if ( ans != - 1 ) { return ans ; } ans = 0 ; for ( let i = 0 ; i <= 9 ; ++ i ) { if ( count == 0 && previous != i ) { ans = ( ans + ( findCountUtil ( N , maxDigit , position + 1 , i , maxDigit [ i ] - 1 ) ) % MOD ) % MOD ; } else if ( count != 0 ) { ans = ( ans + ( findCountUtil ( N , maxDigit , position + 1 , i , ( previous == i && position != 0 ) ? count - 1 : maxDigit [ i ] - 1 ) ) % MOD ) % MOD ; } } return ans ; } function findCount ( N , maxDigit ) { let position = 0 ; let previous = 0 ; let count = 1 ; let ans = findCountUtil ( N , maxDigit , position , previous , count ) ; document . write ( ans ) ; } let N = 2 ; let maxDigit = [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ; findCount ( N , maxDigit ) ;

Index/key variables: count, i, j, k, position, previous
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function findMinDiff ( arr , n ) { arr . sort ( function ( a , b ) { return a - b } ) ; let diff = Number . MAX_VALUE ; for ( let i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ; return diff ; } let arr = [ 1 , 5 , 3 , 19 , 18 , 25 ] ; document . write ( " " + findMinDiff ( arr , arr . length ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let a = 2 , b = 10 ; let size = Math . abs ( b - a ) + 1 ; let array = [ ] ; for ( let i = a ; i <= b ; i ++ ) if ( i % 2 == 0 i % 5 == 0 ) array [ i - a ] = 1 ; document . write ( " " + " " + " " ) ; for ( let i = a ; i <= b ; i ++ ) if ( array [ i - a ] == 1 ) document . write ( i + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
class Node { constructor ( val ) { this . key = val ; this . left = null ; this . right = null ; } } var root = null ; function printPostorder ( node ) { if ( node == null ) return ; printPostorder ( node . left ) ; printPostorder ( node . right ) ; document . write ( node . key + " " ) ; } function printInorder ( node ) { if ( node == null ) return ; printInorder ( node . left ) ; document . write ( node . key + " " ) ; printInorder ( node . right ) ; } function printPreorder ( node ) { if ( node == null ) return ; document . write ( node . key + " " ) ; printPreorder ( node . left ) ; printPreorder ( node . right ) ; } root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; document . write ( " " ) ; printPreorder ( root ) ; document . write ( " " ) ; printInorder ( root ) ; document . write ( " " ) ; printPostorder ( root ) ;

Class/struct names: Node
Javascript program:
function swapEvenOdd ( arr , N ) { let stack = [ ] ; stack . push ( [ 0 , arr [ 0 ] ] ) ; for ( let i = 1 ; i < N ; i ++ ) { if ( stack . length != 0 ) { if ( arr [ i ] % 2 != stack [ stack . length - 1 ] [ 1 ] % 2 ) { let pop = stack . pop ( ) ; let index = pop [ 0 ] , val = pop [ 1 ] ; arr [ index ] = arr [ i ] ; arr [ i ] = val ; } else stack . push ( [ i , arr [ i ] ] ) ; } else stack . push ( [ i , arr [ i ] ] ) ; } for ( let i = 0 ; i < N ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 1 , 3 , 2 , 4 ] ; let N = arr . length ; swapEvenOdd ( arr , N ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
var M = 100 ; function mxSubSum ( i , arr , j , dp ) { if ( i == 0 ) { dp [ i ] [ j ] = Math . max ( 0 , arr [ i ] ) ; return dp [ i ] [ j ] ; } if ( dp [ i ] [ j ] != - 1 ) { return dp [ i ] [ j ] ; } var X = Math . max ( 0 , arr [ i ] + mxSubSum ( i - 1 , arr , j , dp ) ) ; if ( j == 0 ) { dp [ i ] [ j ] = X ; return dp [ i ] [ j ] } var Y = mxSubSum ( i - 1 , arr , j - 1 , dp ) ; dp [ i ] [ j ] = Math . max ( X , Y ) ; return dp [ i ] [ j ] } function MaximumSubarraySum ( n , arr , k ) { var dp = Array . from ( Array ( M ) , ( ) => Array ( M ) . fill ( - 1 ) ) ; mxSubSum ( n - 1 , arr , k , dp ) ; var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j <= k ; j ++ ) { res = Math . max ( res , dp [ i ] [ j ] ) ; } } if ( arr . reduce ( ( a , b ) => Math . max ( a , b ) ) < 0 ) { res = arr . reduce ( ( a , b ) => Math . max ( a , b ) ) ; } return res ; } var arr = [ - 2 , 1 , 3 , - 2 , 4 , - 7 , 20 ] ; var K = 1 ; var N = arr . length ; document . write ( MaximumSubarraySum ( N , arr , K ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let prime = [ ] ; function sieve ( n ) { prime = new Array ( n + 1 ) ; for ( let i = 0 ; i < prime . length ; i ++ ) prime [ i ] = true ; for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } function MinWays ( a , n , m ) { let dp = new Array ( 1 << m ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = n + 1 ; } for ( let i = 0 ; i < a . length ; i ++ ) { let bitmask = BitMask ( a [ i ] ) ; for ( let j = ( 1 << m ) - 1 ; j >= 0 ; j -- ) { if ( dp [ j ] != n + 1 ) { dp [ j bitmask ] = Math . min ( dp [ j bitmask ] , dp [ j ] + 1 ) ; } } dp [ bitmask ] = 1 ; } return ( dp [ ( 1 << m ) - 1 ] - 1 ) == ( n + 1 ) ? - 1 : ( dp [ ( 1 << m ) - 1 ] - 1 ) ; } function BitMask ( a ) { let bitmask = 0 ; for ( let i = 0 ; i < a . length ; i ++ ) { if ( prime [ a [ i ] ] ) { bitmask |= ( 1 << i ) ; } } return bitmask ; } let mat = [ [ 4 , 6 , 5 , 8 ] , [ 2 , 9 , 12 , 14 ] , [ 32 , 7 , 18 , 16 ] , [ 12 , 4 , 35 , 17 ] ] ; let m = mat [ 0 ] . length ; let n = mat . length ; let max = 10000 ; sieve ( max ) ; document . write ( MinWays ( mat , n , m ) ) ;

Index/key variables: bitmask, i, j, p
Accumulator variables: bitmask, i, j, p
Iterator variables: i, j, p
Javascript program:
let INF = 10000 ; function minCost ( arr , n ) { arr . sort ( ) ; let m = 2 * n ; let cost = new Array ( n + 1 ) ; for ( var i = 0 ; i < cost . length ; i ++ ) { cost [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i <= n ; i ++ ) { for ( let j = 0 ; j <= m ; j ++ ) { cost [ i ] [ j ] = INF ; } } cost [ 0 ] [ 0 ] = 0 ; let prev = 0 ; for ( let i = 1 ; i <= n ; i ++ ) { prev = cost [ i - 1 ] [ 0 ] ; for ( let j = 1 ; j <= m ; j ++ ) { cost [ i ] [ j ] = Math . min ( cost [ i ] [ j ] , prev + Math . abs ( j - arr [ i - 1 ] ) ) ; prev = Math . min ( prev , cost [ i - 1 ] [ j ] ) ; } } let minCost = INF ; for ( let j = 1 ; j <= m ; j ++ ) { minCost = Math . min ( minCost , cost [ n ] [ j ] ) ; } document . write ( minCost ) ; } let arr = [ 4 , 2 , 4 , 4 , 5 , 2 ] ; let N = arr . length ; minCost ( arr , N ) ;

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function checkbit ( array , index ) { return array [ index >> 5 ] & ( 1 << ( index & 31 ) ) ; } function setbit ( array , index ) { array [ index >> 5 ] |= ( 1 << ( index & 31 ) ) ; } let a = 2 , b = 10 ; let size = Math . abs ( b - a ) ; size = Math . ceil ( size / 32 ) ; let array = new Array ( size ) ; for ( let i = a ; i <= b ; i ++ ) if ( i % 2 == 0 i % 5 == 0 ) setbit ( array , i - a ) ; document . write ( " " ) ; for ( let i = a ; i <= b ; i ++ ) if ( checkbit ( array , i - a ) ) document . write ( i + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
let arr1 = [ 0 , 1 , 0 , 1 , 1 , 1 , 1 ] ; let arr2 = [ 1 , 1 , 1 , 1 , 1 , 0 , 1 ] ; function longestCommonSum ( n ) { let maxLen = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let sum1 = 0 , sum2 = 0 ; for ( let j = i ; j < n ; j ++ ) { sum1 += arr1 [ j ] ; sum2 += arr2 [ j ] ; if ( sum1 == sum2 ) { let len = j - i + 1 ; if ( len > maxLen ) maxLen = len ; } } } return maxLen ; } document . write ( " " + " " ) ; document . write ( longestCommonSum ( arr1 . length ) ) ;

Index/key variables: j
Accumulator variables: i, j, sum1, sum2
Iterator variables: i, j
Javascript program:
function findNumberOfLIS ( nums ) { if ( nums . length == 0 ) return 0 ; var n = nums . length ; var dp_l = Array ( n ) . fill ( 1 ) ; var dp_c = Array ( n ) . fill ( 1 ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < i ; j ++ ) { if ( nums [ i ] <= nums [ j ] ) continue ; if ( dp_l [ j ] + 1 > dp_l [ i ] ) { dp_l [ i ] = dp_l [ j ] + 1 ; dp_c [ i ] = dp_c [ j ] ; } else if ( dp_l [ j ] + 1 == dp_l [ i ] ) dp_c [ i ] += dp_c [ j ] ; } } var max_length = 0 ; dp_l . forEach ( i => { max_length = Math . max ( i , max_length ) ; } ) ; var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( dp_l [ i ] == max_length ) count += dp_c [ i ] ; } return count ; } var arr = [ 1 , 3 , 5 , 4 , 7 ] ; document . write ( findNumberOfLIS ( arr ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
class Node { constructor ( data ) { this . left = null ; this . right = null ; this . val = data ; } } function newNode ( data ) { let temp = new Node ( data ) ; return temp ; } function checkEvenOddLevel ( root ) { if ( root == null ) return true ; let q = [ ] ; q . push ( root ) ; let level = 0 ; while ( q . length > 0 ) { let list = [ ] ; let size = q . length ; for ( let i = 0 ; i < size ; i ++ ) { let node = q [ 0 ] ; q . shift ( ) ; list . push ( node . val ) ; if ( node . left != null ) q . push ( node . left ) ; if ( node . right != null ) q . push ( node . right ) ; } if ( level % 2 == 0 ) { for ( let i = 0 ; i < list . length - 1 ; i ++ ) { if ( list [ i + 1 ] > list [ i ] ) continue ; return false ; } } else if ( level % 2 == 1 ) { for ( let i = 0 ; i < list . length - 1 ; i ++ ) { if ( list [ i + 1 ] < list [ i ] ) continue ; return false ; } } level ++ ; } return true ; } let root = null ; root = newNode ( 2 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 7 ) ; root . right . right = newNode ( 11 ) ; root . left . left . left = newNode ( 10 ) ; root . left . left . right = newNode ( 5 ) ; root . left . right . right = newNode ( 1 ) ; if ( checkEvenOddLevel ( root ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i
Accumulator variables: i, level
Iterator variables: i
Class/struct names: Node
Javascript program:
let maxN = 20 ; let dp = new Array ( maxN ) ; function solve ( s , n , idx , k , last , count ) { if ( k < 0 ) return n + 1 ; if ( idx == n ) return 0 ; let ans = dp [ idx ] [ k ] [ last - ' ' . charCodeAt ( ) ] [ count ] ; if ( ans != - 1 ) return ans ; ans = n + 1 ; ans = Math . min ( ans , solve ( s , n , idx + 1 , k - 1 , last , count ) ) ; let inc = 0 ; if ( count == 1 count == 9 count == 99 ) inc = 1 ; if ( last == s [ idx ] . charCodeAt ( ) ) { ans = Math . min ( ans , inc + solve ( s , n , idx + 1 , k , s [ idx ] . charCodeAt ( ) , count + 1 ) ) ; } else { ans = Math . min ( ans , 1 + solve ( s , n , idx + 1 , k , s [ idx ] . charCodeAt ( ) , 1 ) ) ; } dp [ idx ] [ k ] [ last - ' ' . charCodeAt ( ) ] [ count ] = ans ; return dp [ idx ] [ k ] [ last - ' ' . charCodeAt ( ) ] [ count ] ; } function MinRunLengthEncoding ( s , n , k ) { for ( let i = 0 ; i < maxN ; i ++ ) { dp [ i ] = new Array ( maxN ) ; for ( let j = 0 ; j < maxN ; j ++ ) { dp [ i ] [ j ] = new Array ( 27 ) ; for ( let k = 0 ; k < 27 ; k ++ ) { dp [ i ] [ j ] [ k ] = new Array ( maxN ) ; for ( let l = 0 ; l < maxN ; l ++ ) { dp [ i ] [ j ] [ k ] [ l ] = - 1 ; } } } } return solve ( s , n , 0 , k , 123 , 0 ) ; } let S = " " ; let N = 9 , K = 2 ; document . write ( MinRunLengthEncoding ( S , N , K ) ) ;

Index/key variables: count, i, idx, j, k, l
Accumulator variables: i, j, k, l
Iterator variables: i, j, k, l
Javascript program:
let countPaths = 0 ; function CountUniquePaths ( a , i , j , m , n , ans ) { if ( i >= m j >= n ) return ; if ( i == m - 1 && j == n - 1 ) { let sr = Math . sqrt ( ans * a [ i ] [ j ] ) ; if ( ( sr - Math . floor ( sr ) ) == 0 ) countPaths ++ ; } CountUniquePaths ( a , i + 1 , j , m , n , ans * a [ i ] [ j ] ) ; CountUniquePaths ( a , i , j + 1 , m , n , ans * a [ i ] [ j ] ) ; } let M = 3 , N = 2 ; let mat = [ [ 1 , 1 ] , [ 3 , 1 ] , [ 3 , 1 ] ] ; CountUniquePaths ( mat , 0 , 0 , M , N , 1 ) ; document . write ( countPaths ) ;

Index/key variables: i, j
Accumulator variables: countPaths