dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findSetBits ( n ) { let dp = new Array ( n + 1 ) ; dp . fill ( 0 ) ; document . write ( dp [ 0 ] + " " ) ; for ( let i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) { dp [ i ] = dp [ parseInt ( i / 2 , 10 ) ] ; } else { dp [ i ] = dp [ parseInt ( i / 2 , 10 ) ] + 1 ; } document . write ( dp [ i ] + " " ) ; } } let n = 5 ; findSetBits ( n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function sortArr ( arr , n ) { let i , cnt0 = 0 , cnt1 = 0 , cnt2 = 0 ; for ( i = 0 ; i < n ; i ++ ) { switch ( arr [ i ] ) { case 0 : cnt0 ++ ; break ; case 1 : cnt1 ++ ; break ; case 2 : cnt2 ++ ; break ; } } i = 0 ; while ( cnt0 > 0 ) { arr [ i ++ ] = 0 ; cnt0 -- ; } while ( cnt1 > 0 ) { arr [ i ++ ] = 1 ; cnt1 -- ; } while ( cnt2 > 0 ) { arr [ i ++ ] = 2 ; cnt2 -- ; } printArr ( arr , n ) ; } let arr = [ 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 ] ; let n = arr . length ; sortArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: cnt0, cnt1, cnt2, i
Iterator variables: i
Javascript program:
let row = 6 ; let col = 8 ; function cal ( hist , n ) { let s = [ ] ; let max_area = 0 ; let tp ; let area_with_top ; let i = 0 ; while ( i < n ) { if ( s . length == 0 hist [ s [ s . length - 1 ] ] <= hist [ i ] ) s . push ( i ++ ) ; else { tp = s [ s . length - 1 ] ; s . pop ( ) ; area_with_top = hist [ tp ] * ( s . length == 0 ? i : i - s [ s . length - 1 ] - 1 ) ; if ( max_area < area_with_top ) max_area = area_with_top ; } } while ( s . length != 0 ) { tp = s [ s . length - 1 ] ; s . pop ( ) ; area_with_top = hist [ tp ] * ( s . length == 0 ? i : i - s [ s . length - 1 ] - 1 ) ; if ( max_area < area_with_top ) max_area = area_with_top ; } return max_area ; } function largestMatrix ( a ) { let dp = new Array ( row ) ; for ( let i = 0 ; i < row ; i ++ ) { dp [ i ] = new Array ( col ) ; } for ( let i = 0 ; i < col ; i ++ ) { let cnt = 0 ; for ( let j = row - 1 ; j >= 0 ; j -- ) { dp [ j ] [ i ] = 0 ; if ( a [ j ] [ i ] == 1 ) { cnt ++ ; dp [ j ] [ i ] = cnt ; } else { cnt = 0 ; } } } let ans = - 1 ; for ( let i = 0 ; i < row ; i ++ ) { let hist = new Array ( col ) ; for ( let j = 0 ; j < col ; j ++ ) { hist [ j ] = dp [ i ] [ j ] ; } ans = Math . max ( ans , cal ( hist , col ) ) ; } for ( let i = 0 ; i < col ; i ++ ) { let cnt = 0 ; for ( let j = row - 1 ; j >= 0 ; j -- ) { dp [ j ] [ i ] = 0 ; if ( a [ j ] [ i ] == 0 ) { cnt ++ ; dp [ j ] [ i ] = cnt ; } else { cnt = 0 ; } } } for ( let i = 0 ; i < row ; i ++ ) { let hist = new Array ( col ) ; for ( let j = 0 ; j < col ; j ++ ) { hist [ j ] = dp [ i ] [ j ] ; } ans = Math . max ( ans , cal ( hist , col ) ) ; } return ans ; } let a = [ [ 1 , 1 , 0 , 1 , 0 , 0 , 0 , 0 ] , [ 0 , 1 , 1 , 1 , 1 , 0 , 0 , 1 ] , [ 1 , 0 , 0 , 1 , 1 , 1 , 0 , 0 ] , [ 0 , 1 , 1 , 0 , 1 , 1 , 0 , 0 ] , [ 1 , 0 , 1 , 1 , 1 , 1 , 1 , 0 ] , [ 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 ] ] ; document . write ( largestMatrix ( a ) ) ;

Index/key variables: i, j, tp
Accumulator variables: cnt, i, j
Iterator variables: i, j
Javascript program:
function printUnsorted ( arr , n ) { let s = 0 , e = n - 1 , i , max , min ; for ( s = 0 ; s < n - 1 ; s ++ ) { if ( arr [ s ] > arr [ s + 1 ] ) break ; } if ( s == n - 1 ) { document . write ( " " ) ; return ; } for ( e = n - 1 ; e > 0 ; e -- ) { if ( arr [ e ] < arr [ e - 1 ] ) break ; } max = arr [ s ] ; min = arr [ s ] ; for ( i = s + 1 ; i <= e ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; if ( arr [ i ] < min ) min = arr [ i ] ; } for ( i = 0 ; i < s ; i ++ ) { if ( arr [ i ] > min ) { s = i ; break ; } } for ( i = n - 1 ; i >= e + 1 ; i -- ) { if ( arr [ i ] < max ) { e = i ; break ; } } document . write ( " " + " " + " " + s + " " + e ) ; return ; } let arr = [ 10 , 12 , 20 , 30 , 25 , 40 , 32 , 31 , 35 , 50 , 60 ] ; let arr_size = arr . length ; printUnsorted ( arr , arr_size ) ;

Index/key variables: e, i, s
Accumulator variables: e, i, s
Iterator variables: e, i, s
Javascript program:
function findNumberOfTriangles ( arr , n ) { let count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { for ( let k = j + 1 ; k < n ; k ++ ) if ( arr [ i ] + arr [ j ] > arr [ k ] && arr [ i ] + arr [ k ] > arr [ j ] && arr [ k ] + arr [ j ] > arr [ i ] ) count ++ ; } } return count ; } let arr = [ 10 , 21 , 22 , 100 , 101 , 200 , 300 ] ; let size = arr . length ; document . write ( " " + findNumberOfTriangles ( arr , size ) ) ;

Index/key variables: i, j, k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Javascript program:
function findNumberOfTriangles ( arr ) { let n = arr . length ; arr . sort ( ( a , b ) => a - b ) ; let count = 0 ; for ( let i = 0 ; i < n - 2 ; ++ i ) { let k = i + 2 ; for ( let j = i + 1 ; j < n ; ++ j ) { while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ; if ( k > j ) count += k - j - 1 ; } } return count ; } let arr = [ 10 , 21 , 22 , 100 , 101 , 200 , 300 ] ; let size = arr . length ; document . write ( " " + findNumberOfTriangles ( arr , size ) ) ;

Index/key variables: i, j, k
Accumulator variables: count
Iterator variables: i, j
Javascript program:
function CountTriangles ( A ) { var n = A . length ; A . sort ( ) ; var count = 0 ; for ( i = n - 1 ; i >= 1 ; i -- ) { var l = 0 , r = i - 1 ; while ( l < r ) { if ( A [ l ] + A [ r ] > A [ i ] ) { count += r - l ; r -- ; } else { l ++ ; } } } document . write ( " " + count ) ; } var A = [ 4 , 3 , 5 , 7 , 6 ] ; CountTriangles ( A ) ;

Index/key variables: i, l, r
Accumulator variables: count, i, l, r
Iterator variables: i
Javascript program:
function countPairsBruteForce ( X , Y , m , n ) { let ans = 0 ; for ( let i = 0 ; i < m ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { if ( ( Math . pow ( X [ i ] , Y [ j ] ) > Math . pow ( Y [ j ] , X [ i ] ) ) ) { ans += 1 ; } } } return ans ; }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
let v = [ ] ; let dp = [ ] ; let exp_c = [ ] ; function FindMax ( i , r , w , n , c , k ) { if ( i >= n ) { return 0 ; } if ( v [ i ] [ r ] ) { return dp [ i ] [ r ] ; } v [ i ] [ r ] = true ; dp [ i ] [ r ] = FindMax ( i + 1 , r , w , n , c , k ) ; for ( let j = 0 ; j < k ; j ++ ) { let x = ( r / exp_c [ j ] ) % ( c + 1 ) ; if ( x - w [ i ] >= 0 ) { dp [ i ] [ r ] = Math . max ( dp [ i ] [ r ] , w [ i ] + FindMax ( i + 1 , r - w [ i ] * exp_c [ j ] , w , n , c , k ) ) ; } } return dp [ i ] [ r ] ; } function PreCompute ( n , c , k ) { for ( let i = 0 ; i < k ; i ++ ) { exp_c . push ( 0 ) ; } exp_c [ 0 ] = 1 ; for ( let i = 1 ; i < k ; i ++ ) { exp_c [ i ] = ( exp_c [ i - 1 ] * ( c + 1 ) ) ; } for ( let i = 0 ; i < n ; i ++ ) { dp . push ( [ ] ) ; } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < ( exp_c [ k - 1 ] * ( c + 1 ) ) ; j ++ ) { dp [ i ] [ 0 ] ; } } for ( let i = 0 ; i < n ; i ++ ) { v . push ( [ ( exp_c [ k - 1 ] * ( c + 1 ) ) ] ) ; } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < v [ i ] . length ; j ++ ) { v [ i ] [ j ] = false ; } } let R = 0 ; for ( let i = 0 ; i < k ; i ++ ) { R += exp_c [ i ] * c ; } return R ; } let w = [ 3 , 8 , 9 ] ; let k = 1 , c = 11 ; let n = w . length ; let r = PreCompute ( n , c , k ) ; document . write ( FindMax ( 0 , r , w , n , c , k ) ) ;

Index/key variables: i, j, r
Accumulator variables: R, i, j
Iterator variables: i, j
Javascript program:
function countPairsWithDiffK ( arr , n , k ) { count = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] - arr [ j ] == k arr [ j ] - arr [ i ] == k ) count ++ ; } return count ; } arr = new Array ( 1 , 5 , 3 , 4 , 2 ) ; n = arr . length ; k = 3 ; document . write ( " " + countPairsWithDiffK ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function binarySearch ( arr , low , high , x ) { if ( high >= low ) { let mid = low + Math . floor ( ( high - low ) / 2 ) ; if ( x == arr [ mid ] ) return mid ; if ( x > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , x ) ; else return binarySearch ( arr , low , ( mid - 1 ) , x ) ; } return - 1 ; } function countPairsWithDiffK ( arr , n , k ) { let count = 0 , i ; arr . sort ( ( a , b ) => a - b ) ; for ( i = 0 ; i < n - 1 ; i ++ ) if ( binarySearch ( arr , i + 1 , n - 1 , arr [ i ] + k ) != - 1 ) count ++ ; return count ; } let arr = [ 1 , 5 , 3 , 4 , 2 ] ; let n = arr . length ; let k = 3 ; document . write ( " " + countPairsWithDiffK ( arr , n , k ) ) ;

Index/key variables: i, mid
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function countPairsWithDiffK ( arr , n , k ) { let count = 0 ; arr . sort ( ) ; let l = 0 ; let r = 0 ; while ( r < n ) { if ( arr [ r ] - arr [ l ] == k ) { count ++ ; l ++ ; r ++ ; } else if ( arr [ r ] - arr [ l ] > k ) l ++ ; else r ++ ; } return count ; } let arr = [ 1 , 5 , 3 , 4 , 2 ] ; let n = arr . length ; let k = 3 ; document . write ( " " + countPairsWithDiffK ( arr , n , k ) ) ;

Index/key variables: l, r
Accumulator variables: count, l, r
Javascript program:
let n = 3 ; function findPrefixCount ( p_arr , set_bit ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = n - 1 ; j >= 0 ; j -- ) { if ( set_bit [ i ] [ j ] ) continue ; if ( j != n - 1 ) p_arr [ i ] [ j ] += p_arr [ i ] [ j + 1 ] ; p_arr [ i ] [ j ] += ( ! set_bit [ i ] [ j ] ) ? 1 : 0 ; } } } class pair { constructor ( a , b ) { this . first = a ; this . second = b ; } } function matrixOrValueOne ( set_bit ) { let p_arr = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { p_arr [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) p_arr [ i ] [ j ] = 0 ; } findPrefixCount ( p_arr , set_bit ) ; let count_zero_submatrices = 0 ; for ( let j = 0 ; j < n ; j ++ ) { let i = n - 1 ; let q = [ ] ; let to_sum = 0 ; while ( i >= 0 ) { let c = 0 ; while ( q . length != 0 && q [ q . length - 1 ] . first > p_arr [ i ] [ j ] ) { to_sum -= ( q [ q . length - 1 ] . second + 1 ) * ( q [ q . length - 1 ] . first - p_arr [ i ] [ j ] ) ; c += q [ q . length - 1 ] . second + 1 ; q . pop ( ) ; } to_sum += p_arr [ i ] [ j ] ; count_zero_submatrices += to_sum ; q . push ( new pair ( p_arr [ i ] [ j ] , c ) ) ; i -- ; } } return ( n * ( n + 1 ) * n * ( n + 1 ) ) / 4 - count_zero_submatrices ; } function sumOrMatrix ( arr ) { let sum = 0 ; let mul = 1 ; for ( let i = 0 ; i < 30 ; i ++ ) { let set_bit = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) set_bit [ i ] = new Array ( n ) ; for ( let R = 0 ; R < n ; R ++ ) for ( let C = 0 ; C < n ; C ++ ) set_bit [ R ] [ C ] = ( ( arr [ R ] [ C ] & ( 1 << i ) ) != 0 ) ; sum += ( mul * matrixOrValueOne ( set_bit ) ) ; mul *= 2 ; } return sum ; } let arr = [ [ 9 , 7 , 4 ] , [ 8 , 9 , 2 ] , [ 11 , 11 , 5 ] ] ; document . write ( sumOrMatrix ( arr ) ) ;

Index/key variables: C, R, i, j
Accumulator variables: C, R, c, count_zero_submatrices, i, j, mul, sum, to_sum
Iterator variables: C, R, i, j
Class/struct names: pair
Javascript program:
let MOD = 1000000007 ; function totalSubSets ( n , l , r ) { let zero = Math . floor ( r / 3 ) - Math . ceil ( l / 3 ) + 1 ; let one = Math . floor ( ( r - 1 ) / 3 ) - Math . ceil ( ( l - 1 ) / 3 ) + 1 ; let two = Math . floor ( ( r - 2 ) / 3 ) - Math . ceil ( ( l - 2 ) / 3 ) + 1 ; let dp = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { dp [ i ] = new Array ( 3 ) ; for ( let j = 0 ; j < 3 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } dp [ 0 ] [ 0 ] = zero ; dp [ 0 ] [ 1 ] = one ; dp [ 0 ] [ 2 ] = two ; for ( let i = 1 ; i < n ; ++ i ) { dp [ i ] [ 0 ] = ( ( dp [ i - 1 ] [ 0 ] * zero ) + ( dp [ i - 1 ] [ 1 ] * two ) + ( dp [ i - 1 ] [ 2 ] * one ) ) % MOD ; dp [ i ] [ 1 ] = ( ( dp [ i - 1 ] [ 0 ] * one ) + ( dp [ i - 1 ] [ 1 ] * zero ) + ( dp [ i - 1 ] [ 2 ] * two ) ) % MOD ; dp [ i ] [ 2 ] = ( ( dp [ i - 1 ] [ 0 ] * two ) + ( dp [ i - 1 ] [ 1 ] * one ) + ( dp [ i - 1 ] [ 2 ] * zero ) ) % MOD ; } return dp [ n - 1 ] [ 0 ] ; } let n = 5 ; let l = 10 ; let r = 100 ; document . write ( totalSubSets ( n , l , r ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let r = 4 ; let c = 4 ; function findmatch ( mat , pat , x , y , nrow , ncol , level ) { let l = pat . length ; if ( level == l ) return true ; if ( x < 0 y < 0 x >= nrow y >= ncol ) return false ; if ( mat [ x ] [ y ] == pat [ level ] ) { let temp = mat [ x ] [ y ] ; mat [ x ] [ y ] = ' ' ; let res = findmatch ( mat , pat , x - 1 , y , nrow , ncol , level + 1 ) | findmatch ( mat , pat , x + 1 , y , nrow , ncol , level + 1 ) | findmatch ( mat , pat , x , y - 1 , nrow , ncol , level + 1 ) | findmatch ( mat , pat , x , y + 1 , nrow , ncol , level + 1 ) ; mat [ x ] [ y ] = temp ; return res ; } return false ; } function checkMatch ( mat , pat , nrow , ncol ) { let l = pat . length ; if ( l > nrow * ncol ) return false ; for ( let i = 0 ; i < nrow ; i ++ ) { for ( let j = 0 ; j < ncol ; j ++ ) { if ( mat [ i ] [ j ] == pat [ 0 ] ) if ( findmatch ( mat , pat , i , j , nrow , ncol , 0 ) ) return true ; } } return false ; } let grid = [ " " . split ( ' ' ) , " " . split ( ' ' ) , " " . split ( ' ' ) , " " . split ( ' ' ) ] ; if ( checkMatch ( grid , " " , r , c ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, j, level, x, y
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function constructArr ( arr , pair , n ) { arr [ 0 ] = Math . floor ( ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ) ; for ( let i = 1 ; i < n ; i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ; } let pair = [ 15 , 13 , 11 , 10 , 12 , 10 , 9 , 8 , 7 , 5 ] ; let n = 5 ; let arr = new Array ( n ) ; constructArr ( arr , pair , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function OR ( arr ) { let mOR = 0 ; for ( let i = 0 ; i < arr . length ; ++ i ) { mOR |= arr [ i ] ; } return mOR ; } function maxSubset ( arr , i , curOr , curSize , maxOr ) { if ( i == arr . length ) { if ( curOr == maxOr ) { return curSize ; } else { return arr . length ; } } let take = maxSubset ( arr , i + 1 , curOr arr [ i ] , curSize + 1 , maxOr ) ; let notTake = maxSubset ( arr , i + 1 , curOr , curSize , maxOr ) ; return Math . min ( take , notTake ) ; } let data = [ 5 , 1 , 3 , 4 , 2 ] ; let maxOr = OR ( data ) ; let maxSubsetSize = maxSubset ( data , 0 , 0 , 0 , maxOr ) ; document . write ( maxSubsetSize ) ;

Index/key variables: i
Accumulator variables: mOR
Iterator variables: i
Javascript program:
let arr1 = [ 1 , 5 , 9 , 10 , 15 , 20 ] ; let arr2 = [ 2 , 3 , 8 , 13 ] ; function merge ( m , n ) { for ( let i = n - 1 ; i >= 0 ; i -- ) { let j , last = arr1 [ m - 1 ] ; for ( j = m - 2 ; j >= 0 && arr1 [ j ] > arr2 [ i ] ; j -- ) arr1 [ j + 1 ] = arr1 [ j ] ; if ( j != m - 2 last > arr2 [ i ] ) { arr1 [ j + 1 ] = arr2 [ i ] ; arr2 [ i ] = last ; } } } merge ( arr1 . length , arr2 . length ) ; document . write ( " " ) ; for ( let i = 0 ; i < arr1 . length ; i ++ ) { document . write ( arr1 [ i ] + " " ) ; } document . write ( " " ) ; for ( let i = 0 ; i < arr2 . length ; i ++ ) { document . write ( arr2 [ i ] + " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function gouldSequence ( n ) { for ( var row_num = 1 ; row_num <= n ; row_num ++ ) { var count = 1 ; var c = 1 ; for ( var i = 1 ; i <= row_num ; i ++ ) { c = c * ( row_num - i ) / i ; if ( c % 2 == 1 ) count ++ ; } document . write ( count + " " ) ; } } var n = 16 ; gouldSequence ( n ) ;

Accumulator variables: count, i, row_num
Iterator variables: i, row_num
Javascript program:
let M = 100 ; let N = 100 ; function find_min_odd_cost ( given , m , n ) { let floor = new Array ( M ) ; for ( let i = 0 ; i < M ; i ++ ) { floor [ i ] = new Array ( N ) ; for ( let j = 0 ; j < N ; j ++ ) { floor [ i ] [ j ] = 0 ; } } let min_odd_cost = 0 ; let i , j , temp ; for ( j = 0 ; j < n ; j ++ ) floor [ 0 ] [ j ] = given [ 0 ] [ j ] ; for ( i = 1 ; i < m ; i ++ ) for ( j = 0 ; j < n ; j ++ ) { if ( j == 0 ) { floor [ i ] [ j ] = given [ i ] [ j ] ; floor [ i ] [ j ] += Math . min ( floor [ i - 1 ] [ j ] , floor [ i - 1 ] [ j + 1 ] ) ; } else if ( j == n - 1 ) { floor [ i ] [ j ] = given [ i ] [ j ] ; floor [ i ] [ j ] += Math . min ( floor [ i - 1 ] [ j ] , floor [ i - 1 ] [ j - 1 ] ) ; } else { temp = Math . min ( floor [ i - 1 ] [ j ] , floor [ i - 1 ] [ j - 1 ] ) ; temp = Math . min ( temp , floor [ i - 1 ] [ j + 1 ] ) ; floor [ i ] [ j ] = given [ i ] [ j ] + temp ; } } min_odd_cost = Number . MAX_VALUE ; for ( j = 0 ; j < n ; j ++ ) { if ( floor [ n - 1 ] [ j ] % 2 == 1 ) { if ( min_odd_cost > floor [ n - 1 ] [ j ] ) min_odd_cost = floor [ n - 1 ] [ j ] ; } } if ( min_odd_cost == Number . MIN_VALUE ) return - 1 ; return min_odd_cost ; } let m = 5 , n = 5 ; let given = [ [ 1 , 2 , 3 , 4 , 6 ] , [ 1 , 2 , 3 , 4 , 5 ] , [ 1 , 2 , 3 , 4 , 5 ] , [ 1 , 2 , 3 , 4 , 5 ] , [ 100 , 2 , 3 , 4 , 5 ] ] ; document . write ( " " + find_min_odd_cost ( given , m , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minMaxProduct ( arr1 , arr2 , n1 , n2 ) { let max = arr1 [ 0 ] ; let min = arr2 [ 0 ] ; let i ; for ( i = 1 ; i < n1 && i < n2 ; ++ i ) { if ( arr1 [ i ] > max ) max = arr1 [ i ] ; if ( arr2 [ i ] < min ) min = arr2 [ i ] ; } while ( i < n1 ) { if ( arr1 [ i ] > max ) max = arr1 [ i ] ; i ++ ; } while ( i < n2 ) { if ( arr2 [ i ] < min ) min = arr2 [ i ] ; i ++ ; } return max * min ; } let arr1 = [ 10 , 2 , 3 , 6 , 4 , 1 ] ; let arr2 = [ 5 , 1 , 4 , 2 , 6 , 9 ] ; let n1 = 6 ; let n2 = 6 ; document . write ( minMaxProduct ( arr1 , arr2 , n1 , n2 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getMax ( A , N ) { var B = new Array ( N + 2 ) ; B [ 0 ] = 1 ; B [ N + 1 ] = 1 ; for ( var i = 1 ; i <= N ; i ++ ) B [ i ] = A [ i - 1 ] ; var dp = new Array ( N + 2 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( N + 2 ) . fill ( 0 ) ; } for ( var length = 1 ; length < N + 1 ; length ++ ) { for ( var left = 1 ; left < N - length + 2 ; left ++ ) { var right = left + length - 1 ; for ( var last = left ; last < right + 1 ; last ++ ) { dp [ left ] [ right ] = Math . max ( dp [ left ] [ right ] , dp [ left ] [ last - 1 ] + B [ left - 1 ] * B [ last ] * B [ right + 1 ] + dp [ last + 1 ] [ right ] ) ; } } } return dp [ 1 ] [ N ] ; } var A = [ 1 , 2 , 3 , 4 , 5 ] ; var N = A . length ; document . write ( getMax ( A , N ) ) ;

Index/key variables: N, i, last, left, right
Accumulator variables: i, last, left
Iterator variables: i, last, left
Javascript program:
function findElement ( arr , n , key ) { let i ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == key ) return i ; return - 1 ; } let arr = [ 12 , 34 , 10 , 6 , 40 ] ; let n = arr . length ; let key = 40 ; let position = findElement ( arr , n , key ) ; if ( position == - 1 ) document . write ( " " ) ; else document . write ( " " + ( position + 1 ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function insertSorted ( arr , n , key , capacity ) { if ( n >= capacity ) return n ; arr [ n ] = key ; return ( n + 1 ) ; } let arr = new Array ( 20 ) ; arr [ 0 ] = 12 ; arr [ 1 ] = 16 ; arr [ 2 ] = 20 ; arr [ 3 ] = 40 ; arr [ 4 ] = 50 ; arr [ 5 ] = 70 ; let capacity = 20 ; let n = 6 ; let i , key = 26 ; document . write ( " " ) ; for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; n = insertSorted ( arr , n , key , capacity ) ; document . write ( " " ) ; for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Javascript program:
function findElement ( arr , n , key ) { let i ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == key ) return i ; return - 1 ; } function deleteElement ( arr , n , key ) { let pos = findElement ( arr , n , key ) ; if ( pos == - 1 ) { document . write ( " " ) ; return n ; } let i ; for ( i = pos ; i < n - 1 ; i ++ ) arr [ i ] = arr [ i + 1 ] ; return n - 1 ; } let i ; let arr = [ 10 , 50 , 30 , 40 , 20 ] ; let n = arr . length ; let key = 30 ; document . write ( " " ) ; for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; n = deleteElement ( arr , n , key ) ; document . write ( " " ) ; for ( i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function binarySearch ( arr , low , high , key ) { if ( high < low ) return - 1 ; let mid = Math . trunc ( ( low + high ) / 2 ) ; if ( key == arr [ mid ] ) return mid ; if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ; return binarySearch ( arr , low , ( mid - 1 ) , key ) ; } let arr = [ 5 , 6 , 7 , 8 , 9 , 10 ] ; let n , key ; n = arr . length ; key = 10 ; document . write ( " " + binarySearch ( arr , 0 , n - 1 , key ) + " " ) ;

Index/key variables: mid
Javascript program:
var MAX = 100 var N = 5 var M = 4 function min ( a , b , c ) { return Math . min ( a , Math . min ( b , c ) ) ; } function solveQuery ( n , m , mat , q , a , binary ) { var dp = Array . from ( Array ( n ) , ( ) => Array ( m ) ) ; var max = 1 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < m ; j ++ ) { if ( i == 0 j == 0 ) dp [ i ] [ j ] = 1 ; else if ( ( mat [ i ] [ j ] == mat [ i - 1 ] [ j ] ) && ( mat [ i ] [ j ] == mat [ i ] [ j - 1 ] ) && ( mat [ i ] [ j ] == mat [ i - 1 ] [ j - 1 ] ) ) { dp [ i ] [ j ] = Math . min ( dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] , dp [ i ] [ j - 1 ] ) + 1 ; if ( max < dp [ i ] [ j ] ) max = dp [ i ] [ j ] ; } else dp [ i ] [ j ] = 1 ; } } var freq0 = Array ( MAX ) . fill ( 0 ) ; var freq1 = Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < m ; j ++ ) { if ( mat [ i ] [ j ] == 0 ) freq0 [ dp [ i ] [ j ] ] ++ ; else freq1 [ dp [ i ] [ j ] ] ++ ; } } for ( var i = max - 1 ; i >= 0 ; i -- ) { freq0 [ i ] += freq0 [ i + 1 ] ; freq1 [ i ] += freq1 [ i + 1 ] ; } for ( var i = 0 ; i < q ; i ++ ) { if ( binary [ i ] == 0 ) document . write ( freq0 [ a [ i ] ] + " " ) ; else document . write ( freq1 [ a [ i ] ] + " " ) ; } } var n = 5 , m = 4 ; var mat = [ [ 0 , 0 , 1 , 1 ] , [ 0 , 0 , 1 , 0 ] , [ 0 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 ] , [ 0 , 1 , 1 , 1 ] ] ; var q = 2 ; var a = [ 2 , 2 ] ; var binary = [ 1 , 0 ] ; solveQuery ( n , m , mat , q , a , binary ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function strmatch ( txt , pat , n , m ) { if ( m == 0 ) return ( n == 0 ) ; let i = 0 , j = 0 , index_txt = - 1 , index_pat = - 1 ; while ( i < n ) { if ( j < m && txt [ i ] == pat [ j ] ) { i ++ ; j ++ ; } else if ( j < m && pat [ j ] == ' ' ) { i ++ ; j ++ ; } else if ( j < m && pat [ j ] == ' ' ) { index_txt = i ; index_pat = j ; j ++ ; } else if ( index_pat != - 1 ) { j = index_pat + 1 ; i = index_txt + 1 ; index_txt ++ ; } else { return false ; } } while ( j < m && pat [ j ] == ' ' ) { j ++ ; } if ( j == m ) { return true ; } return false ; } let str = " " . split ( ' ' ) ; let pattern = " " . split ( ' ' ) ; if ( strmatch ( str , pattern , str . length , pattern . length ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; let pattern2 = " " . split ( ' ' ) ; if ( strmatch ( str , pattern2 , str . length , pattern2 . length ) ) document . write ( " " + " " ) ; else document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, index_txt, j
Javascript program:
function findSDSFunc ( n ) { let DP = [ ] ; DP [ 0 ] = 0 ; DP [ 1 ] = 1 ; for ( let i = 2 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ; else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ; } return DP [ n ] ; } let n = 15 ; document . write ( findSDSFunc ( n ) ) ;

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