dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function MaxSumDifference ( a , n ) { let finalSequence = [ ] ; a . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < n / 2 ; ++ i ) { finalSequence . push ( a [ i ] ) ; finalSequence . push ( a [ n - i - 1 ] ) ; } if ( n % 2 != 0 ) finalSequence . push ( a [ Math . floor ( n / 2 ) ] ) ; let MaximumSum = 0 ; for ( let i = 0 ; i < n - 1 ; ++ i ) { MaximumSum = MaximumSum + Math . abs ( finalSequence [ i ] - finalSequence [ i + 1 ] ) ; } MaximumSum = MaximumSum + Math . abs ( finalSequence [ n - 1 ] - finalSequence [ 0 ] ) ; return MaximumSum ; } let a = [ 1 , 2 , 4 , 8 ] ; let n = a . length ; document . write ( MaxSumDifference ( a , n ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function printArray ( array , Length ) { document . write ( " " ) ; for ( let i = 0 ; i < Length ; i ++ ) { document . write ( array [ i ] ) ; if ( i < ( Length - 1 ) ) document . write ( " " ) ; else document . write ( " " ) ; } } function reverse ( array , start , end ) { while ( start < end ) { let temp = array [ start ] ; array [ start ] = array [ end ] ; array [ end ] = temp ; start ++ ; end -- ; } } function rearrange ( array , start , end ) { if ( start == end ) return ; rearrange ( array , ( start + 1 ) , end ) ; if ( array [ start ] >= 0 ) { reverse ( array , ( start + 1 ) , end ) ; reverse ( array , start , end ) ; } } let array = [ - 12 , - 11 , - 13 , - 5 , - 6 , 7 , 5 , 3 , 6 ] ; let length = array . length ; let countNegative = 0 ; for ( let i = 0 ; i < length ; i ++ ) { if ( array [ i ] < 0 ) countNegative ++ ; } document . write ( " " ) ; printArray ( array , length ) ; rearrange ( array , 0 , ( length - 1 ) ) ; reverse ( array , countNegative , ( length - 1 ) ) ; document . write ( " " ) ; printArray ( array , length ) ;

Index/key variables: end, i, start
Accumulator variables: countNegative, end, i, start
Iterator variables: i
Javascript program:
function mergeArray ( arr1 , arr2 , n , m ) { for ( let i = 0 ; i < n ; i ++ ) { if ( arr1 [ i ] > arr2 [ 0 ] ) { let temp = arr1 [ i ] ; arr1 [ i ] = arr2 [ 0 ] ; arr2 [ 0 ] = temp ; let firstElement = arr2 [ 0 ] ; let k ; for ( k = 1 ; k < m && arr2 [ k ] < firstElement ; k ++ ) { arr2 [ k - 1 ] = arr2 [ k ] ; } arr2 [ k - 1 ] = firstElement ; } } for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr1 [ i ] + " " ) ; } document . write ( " " ) ; for ( let i = 0 ; i < m ; i ++ ) { document . write ( arr2 [ i ] + " " ) ; } } let arr1 = [ 1 , 3 , 5 , 7 ] ; let arr2 = [ 0 , 2 , 6 , 8 , 9 ] ; let n = 4 , m = 5 ; mergeArray ( arr1 , arr2 , n , m ) ;

Index/key variables: i, k
Accumulator variables: i, k
Iterator variables: i, k
Javascript program:
function maxProductSubarrayOfSizeK ( A , n , k ) { A . sort ( function ( a , b ) { return a - b } ) ; let product = 1 ; let i ; if ( A [ n - 1 ] == 0 && k % 2 != 0 ) return 0 ; if ( A [ n - 1 ] <= 0 && k % 2 != 0 ) { for ( i = n - 1 ; i >= n - k ; i -- ) product *= A [ i ] ; return product ; } i = 0 ; let j = n - 1 ; if ( k % 2 != 0 ) { product *= A [ j ] ; j -- ; k -- ; } k >>= 1 ; for ( let itr = 0 ; itr < k ; itr ++ ) { let left_product = A [ i ] * A [ i + 1 ] ; let right_product = A [ j ] * A [ j - 1 ] ; if ( left_product > right_product ) { product *= left_product ; i += 2 ; } else { product *= right_product ; j -= 2 ; } } return product ; } let A = [ 1 , 2 , - 1 , - 3 , - 6 , 4 ] ; let n = A . length ; let k = 4 ; document . write ( maxProductSubarrayOfSizeK ( A , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, itr, j, k, product
Iterator variables: i, itr
Javascript program:
function reorder ( arr , index , n ) { var temp = [ ... Array ( n ) ] ; for ( var i = 0 ; i < n ; i ++ ) temp [ index [ i ] ] = arr [ i ] ; for ( var i = 0 ; i < n ; i ++ ) { arr [ i ] = temp [ i ] ; index [ i ] = i ; } } var arr = [ 50 , 40 , 70 , 60 , 90 ] ; var index = [ 3 , 0 , 4 , 1 , 2 ] ; var n = arr . length ; reorder ( arr , index , n ) ; document . write ( " " ) ; document . write ( " " ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; document . write ( " " ) ; document . write ( " " ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( index [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function selectionSort ( arr , n ) { for ( let i = 0 ; i < n - 1 ; i ++ ) { let min_index = i ; let minStr = arr [ i ] ; for ( let j = i + 1 ; j < n ; j ++ ) { if ( ( arr [ j ] ) . localeCompare ( minStr ) === - 1 ) { minStr = arr [ j ] ; min_index = j ; } } if ( min_index != i ) { let temp = arr [ min_index ] ; arr [ min_index ] = arr [ i ] ; arr [ i ] = temp ; } } } let arr = [ " " , " " , " " ] ; let n = arr . length ; document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( i + " " + arr [ i ] + " " ) ; } document . write ( " " ) ; selectionSort ( arr , n ) ; document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( i + " " + arr [ i ] + " " ) ; }

Index/key variables: i, j, min_index
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function reorder ( arr , index , n ) { for ( let i = 0 ; i < n ; i ++ ) { while ( index [ i ] != i ) { let oldTargetI = index [ index [ i ] ] ; let oldTargetE = arr [ index [ i ] ] ; arr [ index [ i ] ] = arr [ i ] ; index [ index [ i ] ] = index [ i ] ; index [ i ] = oldTargetI ; arr [ i ] = oldTargetE ; } } } let arr = [ 50 , 40 , 70 , 60 , 90 ] ; let index = [ 3 , 0 , 4 , 1 , 2 ] ; let n = arr . length ; reorder ( arr , index , n ) ; document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( index [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function stoogesort ( arr , l , h ) { if ( l >= h ) return ; if ( arr [ l ] > arr [ h ] ) { let t = arr [ l ] ; arr [ l ] = arr [ h ] ; arr [ h ] = t ; } if ( h - l + 1 > 2 ) { let t = parseInt ( ( h - l + 1 ) / 3 , 10 ) ; stoogesort ( arr , l , h - t ) ; stoogesort ( arr , l + t , h ) ; stoogesort ( arr , l , h - t ) ; } } let arr = [ 2 , 4 , 5 , 3 , 1 ] ; let n = arr . length ; stoogesort ( arr , 0 , n - 1 ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: h, i, l
Accumulator variables: i
Iterator variables: i
Javascript program:
function numofsubset ( arr , n ) { arr . sort ( ( a , b ) => a - b ) ; var count = 1 ; for ( i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ; } return count ; } var arr = [ 100 , 56 , 5 , 6 , 102 , 58 , 101 , 57 , 7 , 103 , 59 ] ; var n = arr . length ; document . write ( numofsubset ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function gnomeSort ( arr , n ) { let index = 0 ; while ( index < n ) { if ( index == 0 ) index ++ ; if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ; else { let temp = 0 ; temp = arr [ index ] ; arr [ index ] = arr [ index - 1 ] ; arr [ index - 1 ] = temp ; index -- ; } } return ; } let arr = [ 34 , 2 , 10 , - 9 ] ; gnomeSort ( arr , arr . length ) ; document . write ( " " ) ; document . write ( arr . toString ( ) ) ;

Index/key variables: index
Accumulator variables: index
Javascript program:
function cocktailSort ( a ) { let swapped = true ; let start = 0 ; let end = a . length ; while ( swapped == true ) { swapped = false ; for ( let i = start ; i < end - 1 ; ++ i ) { if ( a [ i ] > a [ i + 1 ] ) { let temp = a [ i ] ; a [ i ] = a [ i + 1 ] ; a [ i + 1 ] = temp ; swapped = true ; } } if ( swapped == false ) break ; swapped = false ; end = end - 1 ; for ( let i = end - 1 ; i >= start ; i -- ) { if ( a [ i ] > a [ i + 1 ] ) { let temp = a [ i ] ; a [ i ] = a [ i + 1 ] ; a [ i + 1 ] = temp ; swapped = true ; } } start = start + 1 ; } } function printArray ( a ) { let n = a . length ; for ( let i = 0 ; i < n ; i ++ ) document . write ( a [ i ] + " " ) ; document . write ( " " ) ; } let a = [ 5 , 1 , 4 , 2 , 8 , 0 , 2 ] ; cocktailSort ( a ) ; document . write ( " " + " " ) ; printArray ( a ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: swapped
Javascript program:
function findMaxGuests ( arrl , exit , n ) { arrl . sort ( function ( a , b ) { return a - b } ) ; exit . sort ( function ( a , b ) { return a - b } ) ; let guests_in = 1 , max_guests = 1 , time = arrl [ 0 ] ; let i = 1 , j = 0 ; while ( i < n && j < n ) { if ( arrl [ i ] <= exit [ j ] ) { guests_in ++ ; if ( guests_in > max_guests ) { max_guests = guests_in ; time = arrl [ i ] ; } i ++ ; } else { guests_in -- ; j ++ ; } } document . write ( " " + max_guests + " " + time ) ; } let arrl = [ 1 , 2 , 10 , 5 , 5 ] ; let exit = [ 4 , 5 , 12 , 9 , 12 ] ; let n = arrl . length ; findMaxGuests ( arrl , exit , n ) ;

Index/key variables: i, j
Accumulator variables: guests_in, i, j
Javascript program:
function maxOverlap ( start , end , n ) { let maxa = 0 ; for ( let i = 0 ; i < start . length ; i ++ ) { maxa = Math . max ( maxa , start [ i ] ) ; } let maxb = 0 ; for ( let i = 0 ; i < end . length ; i ++ ) { maxb = Math . max ( maxb , end [ i ] ) ; } let maxc = Math . max ( maxa , maxb ) ; let x = new Array ( maxc + 2 ) ; x . fill ( 0 ) ; let cur = 0 , idx = 0 ; for ( let i = 0 ; i < n ; i ++ ) { ++ x [ start [ i ] ] ; -- x [ end [ i ] + 1 ] ; } let maxy = Number . MIN_VALUE ; for ( let i = 0 ; i <= maxc ; i ++ ) { cur += x [ i ] ; if ( maxy < cur ) { maxy = cur ; idx = i ; } } document . write ( " " + maxy + " " + idx + " " ) ; } let start = [ 13 , 28 , 29 , 14 , 40 , 17 , 3 ] ; let end = [ 107 , 95 , 111 , 105 , 70 , 127 , 74 ] ; let n = start . length ; maxOverlap ( start , end , n ) ;

Index/key variables: i
Accumulator variables: cur, i
Iterator variables: i
Javascript program:
function rearrangeNaive ( arr , n ) { let temp = new Array ( n ) , i ; for ( i = 0 ; i < n ; i ++ ) temp [ arr [ i ] ] = i ; for ( i = 0 ; i < n ; i ++ ) arr [ i ] = temp [ i ] ; } function printArray ( arr , n ) { let i ; for ( i = 0 ; i < n ; i ++ ) document . write ( " " + arr [ i ] ) ; document . write ( " " ) ; } let arr = [ 1 , 3 , 0 , 2 ] ; let n = arr . length ; document . write ( " " ) ; printArray ( arr , n ) ; rearrangeNaive ( arr , n ) ; document . write ( " " ) ; printArray ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function rearrange ( arr , n ) { for ( i = 0 ; i < n ; i ++ ) { arr [ arr [ i ] % n ] += i * n ; } for ( i = 0 ; i < n ; i ++ ) { arr [ i ] = parseInt ( arr [ i ] / n ) ; } } function printArray ( arr , n ) { for ( i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } document . write ( ) ; } var arr = [ 2 , 0 , 1 , 4 , 5 , 3 ] ; var n = arr . length ; document . write ( " " + " " ) ; printArray ( arr , n ) ; rearrange ( arr , n ) ; document . write ( " " ) document . write ( " " + " " ) ; printArray ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function rearrange ( arr , n ) { let temp = new Array ( n ) ; let small = 0 , large = n - 1 ; let flag = true ; for ( let i = 0 ; i < n ; i ++ ) { if ( flag ) temp [ i ] = arr [ large -- ] ; else temp [ i ] = arr [ small ++ ] ; flag = ! flag ; } for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = temp [ i ] ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; rearrange ( arr , n ) ; document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i, large, small
Iterator variables: i
Boolean variables: flag
Javascript program:
function minimumcoins ( arr , N ) { let coins = 0 ; let j = 0 ; if ( arr [ 0 ] == 1 ) coins ++ ; for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == 2 ) continue ; j = i ; while ( j < N && arr [ j ] == 1 ) { j ++ ; } let x = ( j - i ) ; coins += Math . floor ( x / 3 ) ; i = j - 1 ; } return coins ; } let N = 8 ; let arr = [ 1 , 2 , 1 , 1 , 2 , 1 , 1 , 1 ] ; document . write ( minimumcoins ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: coins, i, j
Iterator variables: i
Javascript program:
function rearrange ( arr , n ) { let max_idx = n - 1 , min_idx = 0 ; let max_elem = arr [ n - 1 ] + 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ; max_idx -- ; } else { arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ; min_idx ++ ; } } for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = Math . floor ( arr [ i ] / max_elem ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; let n = arr . length ; document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; rearrange ( arr , n ) ; document . write ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i, max_idx, min_idx
Accumulator variables: i, max_idx, min_idx
Iterator variables: i
Javascript program:
function rearrange ( arr , n ) { let max_ele = arr [ n - 1 ] ; let min_ele = arr [ 0 ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { arr [ i ] = max_ele ; max_ele -= 1 ; } else { arr [ i ] = min_ele ; min_ele += 1 ; } } } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ; let n = arr . length ; document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; rearrange ( arr , n ) ; document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i, max_ele, min_ele
Iterator variables: i
Javascript program:
class Node { constructor ( k ) { this . data = k ; this . left = null ; this . right = null ; } } function isLeaf ( node ) { if ( node == null ) return false ; if ( node . left == null && node . right == null ) return true ; return false ; } function leftLeavesSum ( node ) { let res = 0 ; if ( node != null ) { if ( isLeaf ( node . left ) ) res += node . left . data ; else res += leftLeavesSum ( node . left ) ; res += leftLeavesSum ( node . right ) ; } return res ; } root = new Node ( 20 ) ; root . left = new Node ( 9 ) ; root . right = new Node ( 49 ) ; root . left . right = new Node ( 12 ) ; root . left . left = new Node ( 5 ) ; root . right . left = new Node ( 23 ) ; root . right . right = new Node ( 52 ) ; root . left . right . right = new Node ( 12 ) ; root . right . right . left = new Node ( 50 ) ; document . write ( " " + leftLeavesSum ( root ) ) ;

Accumulator variables: res
Class/struct names: Node
Javascript program:
function rearrange ( arr , n ) { let j = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 0 ) { if ( i != j ) { let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } j ++ ; } } } function printArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ - 1 , 2 , - 3 , 4 , 5 , 6 , - 7 , 8 , 9 ] ; let n = arr . length ; rearrange ( arr , n ) ; printArray ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function maxSum ( arr ) { let m = arr . length ; let n = arr [ 0 ] . length - 1 ; let dp = new Array ( m + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( n + 1 ) . fill ( 0 ) ) ; for ( let i = 1 ; i < m ; ++ i ) dp [ i ] [ 1 ] = arr [ i ] [ 1 ] ; for ( let i = 1 ; i < n + 1 ; ++ i ) { for ( let j = 1 ; j < m ; ++ j ) { let mx = 0 ; for ( let k = 1 ; k < m ; ++ k ) { if ( k != j ) { if ( dp [ k ] [ i - 1 ] > mx ) { mx = dp [ k ] [ i - 1 ] ; } } } if ( mx && arr [ j ] [ i ] ) { dp [ j ] [ i ] = arr [ j ] [ i ] + mx ; } } } let ans = - 1 ; for ( let i = 1 ; i <= m ; ++ i ) { if ( dp [ i ] [ n ] ) { ans = Math . max ( ans , dp [ i ] [ n ] ) } ; } return ans ; } let arr = [ [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 10 , 2 , 20 , 0 ] , [ 0 , 0 , 0 , 5 , 0 ] , [ 0 , 0 , 0 , 0 , 6 ] , [ 0 , 4 , 0 , 11 , 5 ] , [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 ] , ] ; document . write ( maxSum ( arr ) ) ;

Index/key variables: i, j, k, n
Iterator variables: i, j, k
Javascript program:
function segregateElements ( arr , n ) { let temp = new Array ( n ) ; let j = 0 ; for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ; if ( j == n j == 0 ) return ; for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ; for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = temp [ i ] ; } let arr = [ 1 , - 1 , - 3 , - 2 , 7 , 5 , 11 , 6 ] ; let n = arr . length ; segregateElements ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i
Javascript program:
let rearrange = ( arr , n ) => { for ( let i = 0 ; i < n - 1 ; i ++ ) { if ( i % 2 == 0 && arr [ i ] > arr [ i + 1 ] ) { let temp = arr [ i ] ; arr [ i ] = arr [ i + 1 ] ; arr [ i + 1 ] = temp ; } if ( i % 2 != 0 && arr [ i ] < arr [ i + 1 ] ) { let temp = arr [ i ] ; arr [ i ] = arr [ i + 1 ] ; arr [ i + 1 ] = temp ; } } } let printArray = ( arr , size ) => { ans = ' ' ; for ( let i = 0 ; i < size ; i ++ ) { ans += arr [ i ] + " " ; } document . write ( ans ) ; } let arr = [ 6 , 4 , 2 , 1 , 8 , 3 ] ; let n = arr . length ; document . write ( " " ) ; printArray ( arr , n ) ; rearrange ( arr , n ) ; document . write ( " " ) ; document . write ( " " ) ; printArray ( arr , n ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function rearrange ( a , size ) { let positive = 0 ; let negative = 1 ; let temp ; while ( true ) { while ( positive < size && a [ positive ] >= 0 ) positive += 2 ; while ( negative < size && a [ negative ] <= 0 ) negative += 2 ; if ( positive < size && negative < size ) { temp = a [ positive ] ; a [ positive ] = a [ negative ] ; a [ negative ] = temp ; } else break ; } } let arr = [ 1 , - 3 , 5 , 6 , - 3 , 6 , 7 , - 4 , 9 , 10 ] ; let n = arr . length ; rearrange ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i, negative, positive
Accumulator variables: i, negative, positive
Iterator variables: i
Javascript program:
function swap ( a , i , j ) { let temp = a [ i ] ; a [ i ] = a [ j ] ; a [ j ] = temp ; } function printArray ( a , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( a [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ 1 , - 3 , 5 , 6 , - 3 , 6 , 7 , - 4 , 9 , 10 ] ; let n = arr . length ; printArray ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= 0 && i % 2 == 1 ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] < 0 && j % 2 == 0 ) { swap ( arr , i , j ) ; break ; } } } else if ( arr [ i ] < 0 && i % 2 == 0 ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] >= 0 && j % 2 == 1 ) { swap ( arr , i , j ) ; break ; } } } } printArray ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function arrayEvenAndOdd ( arr , n ) { let a = [ ] ; let ind = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { a [ ind ] = arr [ i ] ; ind ++ ; } } for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 != 0 ) { a [ ind ] = arr [ i ] ; ind ++ ; } } for ( let i = 0 ; i < n ; i ++ ) { document . write ( a [ i ] + " " ) ; } document . write ( ' ' ) ; } let arr = [ 1 , 3 , 2 , 4 , 7 , 6 , 9 , 10 ] ; let n = arr . length ; arrayEvenAndOdd ( arr , n ) ;

Index/key variables: i, ind
Accumulator variables: i, ind
Iterator variables: i
Javascript program:
function arrayEvenAndOdd ( arr , n ) { let i = - 1 , j = 0 ; let t ; while ( j != n ) { if ( arr [ j ] % 2 == 0 ) { i ++ ; let temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } j ++ ; } for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 1 , 3 , 2 , 4 , 7 , 6 , 9 , 10 ] ; let n = arr . length ; arrayEvenAndOdd ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
class Node { constructor ( item ) { this . data = item ; this . left = this . right = null ; } } class Sum { constructor ( ) { this . sum = 0 ; } } var root ; function leftLeavesSumRec ( node , isleft , summ ) { if ( node == null ) return ; if ( node . left == null && node . right == null && isleft ) summ . sum = summ . sum + node . data ; leftLeavesSumRec ( node . left , true , summ ) ; leftLeavesSumRec ( node . right , false , summ ) ; } function leftLeavesSum ( node ) { suum = new Sum ( ) ; leftLeavesSumRec ( node , false , suum ) ; return suum . sum ; } root = new Node ( 20 ) ; root . left = new Node ( 9 ) ; root . right = new Node ( 49 ) ; root . left . right = new Node ( 12 ) ; root . left . left = new Node ( 5 ) ; root . right . left = new Node ( 23 ) ; root . right . right = new Node ( 52 ) ; root . left . right . right = new Node ( 12 ) ; root . right . right . left = new Node ( 50 ) ; document . write ( " " + leftLeavesSum ( root ) ) ;

Class/struct names: Node, Sum
Javascript program:
function minimumCost ( str , L , U ) { var N = str . length ; var s = str . split ( " " ) ; string ans = " " ; var lowerFreq = new Array ( 26 ) . fill ( 0 ) ; var upperFreq = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( s [ i ] === s [ i ] . toUpperCase ( ) ) upperFreq [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; else lowerFreq [ s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] ++ ; } var result = new Array ( 26 ) . fill ( 0 ) ; for ( var i = 0 ; i < 26 ; i ++ ) { if ( lowerFreq [ i ] !== 0 upperFreq [ i ] !== 0 ) { var costToUpper = U * lowerFreq [ i ] ; var costToLower = L * upperFreq [ i ] ; if ( costToLower < costToUpper ) { result [ i ] = 1 ; } } } for ( var i = 0 ; i < N ; i ++ ) { var index = 0 ; if ( s [ i ] === s [ i ] . toLowerCase ( ) ) index = s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; else index = s [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; if ( result [ index ] === 1 ) { s [ i ] = s [ i ] . toLowerCase ( ) ; } else { s [ i ] = s [ i ] . toUpperCase ( ) ; } } document . write ( s . join ( " " ) ) ; } var S = " " ; var L = 1 , U = 1 ; minimumCost ( S , L , U ) ;

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Javascript program:
function Check ( A , B , M , N , X ) { for ( var i = 0 ; i < M ; i ++ ) { for ( var j = 0 ; j <= N - X ; j ++ ) { if ( A [ i ] [ j ] != B [ i ] [ j ] ) { var diff = B [ i ] [ j ] - A [ i ] [ j ] ; for ( var k = 0 ; k < X ; k ++ ) { A [ i ] [ j + k ] = A [ i ] [ j + k ] + diff ; } } } } for ( var i = 0 ; i <= M - X ; i ++ ) { for ( var j = 0 ; j < N ; j ++ ) { if ( A [ i ] [ j ] != B [ i ] [ j ] ) { var diff = B [ i ] [ j ] - A [ i ] [ j ] ; for ( var k = 0 ; k < X ; k ++ ) { A [ i + k ] [ j ] = A [ i + k ] [ j ] + diff ; } } } } for ( var i = 0 ; i < M ; i ++ ) { for ( var j = 0 ; j < N ; j ++ ) { if ( A [ i ] [ j ] != B [ i ] [ j ] ) { return 0 ; } } } return 1 ; } var M = 2 , N = 2 , X = 2 ; var A = [ [ 0 , 0 ] , [ 0 , 0 ] ] ; var B = [ [ 1 , 2 ] , [ 0 , 1 ] ] ; if ( Check ( A , B , M , N , X ) ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function minOperations ( arr , N ) { var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { var res = arr [ i ] ; while ( res ) { if ( mp . has ( res ) ) { mp . set ( res , mp . get ( res ) + 1 ) ; } else { mp . set ( res , 1 ) ; } res = parseInt ( res / 2 ) ; } } var mx = 1 ; mp . forEach ( ( value , key ) => { if ( value == N ) { mx = key ; } } ) ; var ans = 0 ; for ( var i = 0 ; i < N ; i ++ ) { var res = arr [ i ] ; while ( res != mx ) { ans ++ ; res = parseInt ( res / 2 ) ; } } document . write ( ans ) ; } var arr = [ 3 , 1 , 1 , 3 ] ; var N = arr . length ; minOperations ( arr , N ) ;

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