dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function lower_bound ( a , low , high , element ) { while ( low < high ) { var middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } function upper_bound ( a , low , high , element ) { while ( low < high ) { var middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } function maxIntersection ( segments , N ) { let rvalues = Array ( N ) . fill ( 0 ) ; let lvalues = Array ( N ) . fill ( 0 ) ; for ( i = 0 ; i < N ; ++ i ) { lvalues [ i ] = segments [ i ] [ 0 ] ; rvalues [ i ] = segments [ i ] [ 1 ] ; } lvalues . sort ( ( a , b ) => a - b ) ; rvalues . sort ( ( a , b ) => a - b ) ; let answer = [ - 1 , - 1 ] ; var numIntersections = 0 ; for ( var i = 0 ; i < N ; ++ i ) { var lesser = lower_bound ( rvalues , 0 , segments . length , segments [ i ] [ 0 ] ) ; var greater = Math . max ( 0 , N - ( upper_bound ( lvalues , 0 , segments . length , segments [ i ] [ 1 ] ) ) ) ; if ( ( N - lesser - greater ) >= numIntersections ) { answer = [ segments [ i ] [ 0 ] , segments [ i ] [ 1 ] ] ; numIntersections = ( N - lesser - greater ) ; } } document . write ( answer [ 0 ] + " " + answer [ 1 ] ) ; } var segments = [ [ 1 , 4 ] , [ 2 , 3 ] , [ 3 , 6 ] ] ; var N = segments . length ; maxIntersection ( segments , N ) ;

Index/key variables: i, middle
Iterator variables: i
Javascript program:
let temp = new Array ( 100000 ) . fill ( 0 ) ; function merge ( A , left , mid , right ) { let swaps = 0 ; let i = left , j = mid , k = left ; while ( i < mid && j <= right ) { if ( A [ i ] <= A [ j ] ) { temp [ k ] = A [ i ] ; k ++ ; i ++ ; } else { temp [ k ] = A [ j ] ; k ++ ; j ++ ; swaps += mid - i ; } } while ( i < mid ) { temp [ k ] = A [ i ] ; k ++ ; i ++ ; } while ( j <= right ) { temp [ k ] = A [ j ] ; k ++ ; j ++ ; } while ( left <= right ) { A [ left ] = temp [ left ] ; left ++ ; } return swaps ; } function mergeInsertionSwap ( A , left , right ) { let swaps = 0 ; if ( left < right ) { let mid = left + ( right - left ) / 2 ; swaps += mergeInsertionSwap ( A , left , mid ) ; swaps += mergeInsertionSwap ( A , mid + 1 , right ) ; swaps += merge ( A , left , mid + 1 , right ) ; } return swaps ; } let A = [ 2 , 1 , 3 , 1 , 2 ] ; let N = A . length ; document . write ( mergeInsertionSwap ( A , 0 , N - 1 ) ) ;

Index/key variables: i, j, k, left
Accumulator variables: i, j, k, left, swaps
Javascript program:
function maxCntRemovedfromArray ( arr , N , brr , M ) { arr . sort ( ) ; let i = 0 ; let sumArr = 0 ; for ( i = 0 ; i < N ; i ++ ) { sumArr += arr [ i ] ; } let sumBrr = 0 ; for ( i = 0 ; i < M ; i ++ ) { sumBrr += brr [ i ] ; } let cntRemElem = 0 ; while ( i < N && sumArr >= sumBrr ) { sumArr -= arr [ i ] ; i += 1 ; if ( sumArr >= sumBrr ) { cntRemElem += 1 ; } } return cntRemElem ; } let arr = [ 1 , 2 , 4 , 6 ] ; let brr = [ 7 ] ; let N = arr . length ; let M = brr . length ; document . write ( maxCntRemovedfromArray ( arr , N , brr , M ) ) ;

Index/key variables: i
Accumulator variables: cntRemElem, i, sumArr, sumBrr
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function findPair ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { let a = arr [ i ] . first , b = arr [ i ] . second ; for ( let j = i + 1 ; j < N ; j ++ ) { let c = arr [ j ] . first , d = arr [ j ] . second ; if ( a < c && b > d ) { document . write ( " " + a + " " + b + " " + c + " " + d + " " ) ; return ; } } } document . write ( " " ) ; } let arr = [ new pair ( 3 , 7 ) , new pair ( 21 , 23 ) , new pair ( 4 , 13 ) , new pair ( 1 , 2 ) , new pair ( 7 , - 1 ) ] ; findPair ( arr , 5 ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: pair
Javascript program:
function findPair ( arr , N ) { arr . sort ( function ( a , b ) { return ( a [ 0 ] - b [ 0 ] ) || ( a [ 1 ] - b [ 1 ] ) ; } ) ; for ( let i = 1 ; i < N ; i ++ ) { let b = arr [ i - 1 ] [ 1 ] ; let d = arr [ i ] [ 1 ] ; if ( b > d ) { console . log ( " " + arr [ i - 1 ] [ 0 ] + " " + b + " " + arr [ i ] [ 0 ] + " " + d + " " ) ; return ; } } console . log ( " " ) ; } var arr = [ [ 3 , 7 ] , [ 21 , 23 ] , [ 4 , 13 ] , [ 1 , 2 ] , [ 7 , - 1 ] ] findPair ( arr , 5 ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printOrder ( order , N , X ) { let vect = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( order [ i ] % X == 0 ) { vect . push ( [ order [ i ] / X , i + 1 ] ) ; } else { vect . push ( [ order [ i ] / X + 1 , i + 1 ] ) ; } } vect . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] } ) ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( vect [ i ] [ 1 ] + " " ) ; } document . write ( ) ; } let N = 3 , X = 3 ; let order = [ 2 , 7 , 4 ] ; printOrder ( order , N , X ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function reverse ( arr , start , end ) { let mid = ( end - start + 1 ) / 2 ; for ( let i = 0 ; i < mid ; i ++ ) { let temp = arr [ start + i ] ; arr [ start + i ] = arr [ end - i ] ; arr [ end - i ] = temp ; } return ; } function shuffleArrayUtil ( arr , start , end ) { let i ; let l = end - start + 1 ; if ( l == 2 ) return ; let mid = start + l / 2 ; if ( l % 4 > 0 ) { mid -= 1 ; } let mid1 = start + ( mid - start ) / 2 ; let mid2 = mid + ( end + 1 - mid ) / 2 ; reverse ( arr , mid1 , mid2 - 1 ) ; reverse ( arr , mid1 , mid - 1 ) ; reverse ( arr , mid , mid2 - 1 ) ; shuffleArrayUtil ( arr , start , mid - 1 ) ; shuffleArrayUtil ( arr , mid , end ) ; } function shuffleArray ( arr , N , start , end ) { shuffleArrayUtil ( arr , start , end ) ; for ( let i = 0 ; i < N ; i ++ ) document . write ( arr [ i ] + " " ) ; } let arr = [ 1 , 3 , 5 , 2 , 4 , 6 ] ; let N = arr . length ; shuffleArray ( arr , N , 0 , N - 1 ) ;

Index/key variables: i
Accumulator variables: i, mid
Iterator variables: i
Javascript program:
function rearrange ( A , B , N , X ) { let flag = true ; A . sort ( ) ; B . sort ( ) ; for ( let i = 0 ; i < N ; i ++ ) { if ( A [ i ] + B [ N - 1 - i ] > X ) { flag = false ; break ; } } if ( flag == true ) document . write ( " " ) ; else document . write ( " " ) ; } let A = [ 1 , 2 , 3 ] ; let B = [ 1 , 1 , 2 ] ; let X = 4 ; let N = A . length ; rearrange ( A , B , N , X ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function numOperation ( arr , N , D ) { arr . sort ( ) ; for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( ( arr [ i + 1 ] - arr [ i ] ) % D != 0 ) { document . write ( " " ) ; return ; } } let count = 0 ; let mid = arr [ N / 2 ] ; for ( let i = 0 ; i < N ; i ++ ) { count += Math . abs ( mid - arr [ i ] ) / D ; } document . write ( count ) ; } let N = 4 , D = 2 ; let arr = [ 2 , 4 , 6 , 8 ] ; numOperation ( arr , N , D ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findSum ( A , N , K ) { A . sort ( ) ; let sum = 0 ; for ( let i = N / K ; i < N ; i += K - 1 ) { sum += A [ i ] ; } document . write ( sum ) ; } let K = 4 ; let A = [ 2 , 3 , 1 , 4 , 7 , 5 , 6 , 1 ] ; let N = A . length ; findSum ( A , N , K ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function findSmallestNumLeft ( arr , N ) { let PQ = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { PQ . push ( arr [ i ] ) ; } PQ . sort ( function ( a , b ) { return b - a ; } ) ; while ( PQ . length > 1 ) { let top1 = PQ [ 0 ] ; PQ . shift ( ) ; let top2 = PQ [ 0 ] ; PQ . shift ( ) ; PQ . push ( Math . floor ( ( top1 + top2 + 1 ) / 2 ) ) ; PQ . sort ( function ( a , b ) { return b - a ; } ) ; } return PQ [ 0 ] ; } let arr = [ 30 , 16 , 40 ] ; let N = arr . length ; document . write ( findSmallestNumLeft ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } function isComposite ( n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; for ( let i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; return false ; } function digitProduct ( number ) { let product = 1 ; while ( number > 0 ) { product *= ( number % 10 ) ; number = Math . floor ( number / 10 ) ; } return product ; } function compositedigitProduct ( num ) { let res = digitProduct ( num ) ; if ( res == 1 ) { return false ; } if ( isComposite ( res ) ) { return true ; } return false ; } function largestCompositeDigitProduct ( a , n , k ) { let pq = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( i % k ) == 0 ) { continue ; } if ( compositedigitProduct ( a [ i ] ) ) { let b = digitProduct ( a [ i ] ) ; pq . push ( new pair ( b , a [ i ] ) ) ; } } pq . sort ( function ( x , y ) { return x . first - y . first } ) ; return pq [ pq . length - 1 ] . second ; } let arr = [ 233 , 144 , 89 , 71 , 13 , 21 , 11 , 34 , 55 , 23 ] ; let n = arr . length ; let k = 3 ; let ans = largestCompositeDigitProduct ( arr , n , k ) ; document . write ( ans + " " ) ;

Index/key variables: i
Accumulator variables: i, product
Iterator variables: i
Class/struct names: pair
Javascript program:
function findMinimum ( arr , N , K ) { arr . sort ( ( a , b ) => a - b ) ; var ans = 0 ; for ( i = 1 ; i < 2 * ( parseInt ( N / K ) ) ; i += 2 ) { ans += arr [ i ] ; } document . write ( ans ) ; } var arr = [ 11 , 20 , 5 , 7 , 8 , 14 , 2 , 17 , 16 , 10 ] ; var N = arr . length ; var K = 5 ; findMinimum ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findSubarrays ( arr , N ) { arr . sort ( ) ; var i = 0 ; for ( i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } var arr = [ 4 , 3 , 0 , 1 , 2 , 0 ] ; var N = arr . length ; findSubarrays ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function Bubble_Sort ( arr , n ) { Boolean ( flag = true ) ; for ( var i = 1 ; i < n ; ++ i ) { flag = false ; for ( var j = 0 ; j <= ( n - i - 1 ) ; ++ j ) { if ( arr [ j ] > arr [ j + 1 ] ) { var temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; flag = true ; } } if ( flag == false ) break ; } } var n = 5 ; var arr = [ 2 , 0 , 1 , 4 , 3 ] ; Bubble_Sort ( arr , n ) ; document . write ( " " + " " ) ; for ( var i = 0 ; i < n ; ++ i ) document . write ( arr [ i ] + " " ) ;

Index/key variables: i, j
Iterator variables: i, j
Boolean variables: flag
Javascript program:
function NDivKWithFreq ( arr , N , K ) { arr . sort ( ) ; for ( let i = 0 ; i < N ; ) { let cnt = 1 ; while ( ( i + 1 ) < N && arr [ i ] == arr [ i + 1 ] ) { cnt ++ ; i ++ ; } if ( cnt > ( N / K ) ) { document . write ( arr [ i ] + " " ) ; } i ++ ; } } let arr = [ 1 , 2 , 2 , 6 , 6 , 6 , 6 , 7 , 10 ] ; let N = arr . length ; let K = 4 ; NDivKWithFreq ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
function printCircularArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } function sortCircularArray ( arr , n , k , m ) { for ( let i = 0 ; i < m ; i ++ ) { for ( let j = k ; j < k + m - 1 ; j ++ ) { if ( arr [ j % n ] > arr [ ( j + 1 ) % n ] ) { let t = arr [ j % n ] ; arr [ j % n ] = arr [ ( j + 1 ) % n ] ; arr [ ( j + 1 ) % n ] = t ; } } } printCircularArray ( arr , n ) ; } let arr = [ 4 , 1 , 6 , 5 , 3 ] ; let K = 2 , M = 3 ; let N = arr . length ; sortCircularArray ( arr , N , K , M ) ;

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function minimumCostReqToCompthePrcess ( arr ) { arr = arr . map ( row => row ) . reverse ( ) var n = arr . length ; var minCost = 0 ; var minCostInit = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] [ 1 ] > minCostInit ) { minCost += ( arr [ i ] [ 1 ] - minCostInit ) ; minCostInit = arr [ i ] [ 1 ] ; } minCostInit -= arr [ i ] [ 0 ] ; } return minCost ; } var arr = [ [ 1 , 2 ] , [ 2 , 4 ] , [ 4 , 8 ] ] ; document . write ( minimumCostReqToCompthePrcess ( arr ) ) ;

Index/key variables: i
Accumulator variables: i, minCost, minCostInit
Iterator variables: i
Javascript program:
function maximumKthLargestsumPart ( arr , N , M , K ) { let maxSum = 0 ; if ( N % M != 0 ) return - 1 ; let sz = ( N / M ) ; if ( K > sz ) return - 1 ; arr . sort ( ) ; let i , k , t ; for ( i = 0 ; i < N / 2 ; i ++ ) { t = arr [ i ] ; arr [ i ] = arr [ N - i - 1 ] ; arr [ N - i - 1 ] = t ; } for ( i = 1 ; i <= M ; i ++ ) { maxSum += arr [ i * K - 1 ] ; } return maxSum ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let M = 2 ; let K = 1 ; let N = arr . length ; document . write ( maximumKthLargestsumPart ( arr , N , M , K ) ) ;

Index/key variables: i
Accumulator variables: i, maxSum
Iterator variables: i
Javascript program:
function minimumRange ( arr , N , K ) { if ( K >= N ) { document . write ( 0 ) ; return ; } arr . sort ( ( a , b ) => a - b ) ; var left = 0 , right = N - 1 , i ; for ( i = 0 ; i < K ; i ++ ) { if ( arr [ right - 1 ] - arr [ left ] < arr [ right ] - arr [ left + 1 ] ) right -- ; else left ++ ; } document . write ( arr [ right ] - arr [ left ] ) ; } var arr = [ 5 , 10 , 12 , 14 , 21 , 54 , 61 ] ; var N = arr . length ; var K = 4 ; minimumRange ( arr , N , K ) ;

Index/key variables: left, right
Accumulator variables: i, left, right
Iterator variables: i
Javascript program:
function splitArray ( arr , n , K ) { arr . sort ( ) ; let i = n - 1 ; let result = 0 ; while ( K -- != 0 ) { result += arr [ i - 1 ] ; i -= 2 ; } document . write ( result ) ; } let arr = [ 1 , 3 , 1 , 5 , 1 , 3 ] ; let N = arr . length ; let K = 2 ; splitArray ( arr , N , K ) ;

Accumulator variables: K, i, result
Javascript program:
function merge ( indices , a , l , mid , r ) { let temp_ind = [ ] ; let j = mid + 1 ; let i = 0 , temp_l = l , k ; while ( l <= mid && j <= r ) { if ( a [ indices [ l ] ] < a [ indices [ j ] ] ) temp_ind [ i ++ ] = indices [ l ++ ] ; else temp_ind [ i ++ ] = indices [ j ++ ] ; } while ( l <= mid ) temp_ind [ i ++ ] = indices [ l ++ ] ; while ( j <= r ) temp_ind [ i ++ ] = indices [ j ++ ] ; for ( k = 0 ; k < i ; k ++ ) indices [ temp_l ++ ] = temp_ind [ k ] ; } function divide ( indices , a , l , r ) { if ( l >= r ) return ; let mid = l / 2 + r / 2 ; divide ( indices , a , l , mid ) ; divide ( indices , a , mid + 1 , r ) ; merge ( indices , a , l , mid , r ) ; } function noOfSubsequences ( arr , N ) { let indices = [ ] ; let i ; for ( i = 0 ; i < N ; i ++ ) indices [ i ] = i ; divide ( indices , arr , 0 , N - 1 ) ; let B = [ ] ; let subseq = 1 ; for ( i = 0 ; i < N ; i ++ ) { B [ indices [ i ] ] = subseq ; subseq *= 2 ; } for ( i = 0 ; i < N ; i ++ ) document . write ( B [ i ] + " " ) ; } let arr = [ 2 , 3 , 1 ] ; let N = arr . length ; noOfSubsequences ( arr , N ) ;

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l, subseq, temp_l
Iterator variables: i, k
Javascript program:
function merge ( order , freq , i , mid , j ) { var tempOrder = Array ( j - i + 1 ) ; var temp = mid + 1 , index = - 1 ; while ( i <= mid && temp <= j ) { if ( freq [ order [ i ] ] <= freq [ order [ temp ] ] ) { tempOrder [ ++ index ] = order [ i ++ ] ; } else { tempOrder [ ++ index ] = order [ temp ++ ] ; } } while ( i <= mid ) { tempOrder [ ++ index ] = order [ i ++ ] ; } while ( temp <= j ) { tempOrder [ ++ index ] = order [ temp ++ ] ; } for ( index ; index >= 0 ; index -- ) { order [ j -- ] = tempOrder [ index ] ; } } function divide ( order , freq , i , j ) { if ( i >= j ) return ; var mid = parseInt ( i / 2 ) + parseInt ( j / 2 ) ; divide ( order , freq , i , mid ) ; divide ( order , freq , mid + 1 , j ) ; merge ( order , freq , i , mid , j ) ; } function orderProcesses ( A , N , q ) { var i = 0 ; var freq = Array ( N ) ; for ( i = 0 ; i < N ; i ++ ) { freq [ i ] = ( A [ i ] / q ) + ( A [ i ] % q > 0 ) ; } var order = Array ( 4 ) ; for ( i = 0 ; i < N ; i ++ ) { order [ i ] = i ; } divide ( order , freq , 0 , N - 1 ) ; for ( i = 0 ; i < N ; i ++ ) { document . write ( order [ i ] + " " ) ; } } var arr = [ 3 , 7 , 4 ] ; var Q = 3 ; var N = arr . length ; orderProcesses ( arr , N , Q ) ;

Index/key variables: i, index, temp
Accumulator variables: i, index, j, temp
Iterator variables: i
Javascript program:
function maxCostToRemove ( arr , N , K ) { let maxCost = 0 ; arr . sort ( ) ; for ( let i = 0 ; i < N ; i += K ) { maxCost += arr [ i + 1 ] ; } return maxCost ; } let arr = [ 1 , 3 , 4 , 1 , 5 , 1 , 5 , 3 ] ; let N = arr . length ; let K = 4 ; document . write ( maxCostToRemove ( arr , N , K ) ) ;

Accumulator variables: i, maxCost
Iterator variables: i
Javascript program:
function convert_to_words ( n ) { let num = ( n ) . toString ( ) . split ( " " ) ; let len = num . length ; let ans = " " ; if ( len == 0 ) { ans += " " ; return ans ; } let single_digits = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let two_digits = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let tens_multiple = [ " " , " " , " " , " " , " " , " " , " " , " " , " " , " " ] ; let tens_power = [ " " , " " ] ; if ( len == 1 ) { ans += single_digits [ num [ 0 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; return ans ; } let x = 0 ; while ( x < num . length ) { if ( len >= 3 ) { if ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) != 0 ) { ans += single_digits [ num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; ans += " " ; ans += tens_power [ len - 3 ] ; ans += " " ; } -- len ; } else { if ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) == 1 ) { let sum = num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) + num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ; ans += two_digits [ sum ] ; return ans ; } else if ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) == 2 && num [ x + 1 ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) == 0 ) { ans += " " ; return ans ; } else { let i = ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ; if ( i > 0 ) { ans += tens_multiple [ i ] ; ans += " " ; } else ans += " " ; ++ x ; if ( num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) != 0 ) ans += single_digits [ num [ x ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ; } } ++ x ; } return " " ; } function lexNumbers ( n ) { let s = [ ] ; for ( let i = 1 ; i <= n ; i ++ ) { s . push ( convert_to_words ( i ) ) ; } s . sort ( ) let ans = [ ] ; for ( let i = 0 ; i < n ; i ++ ) ans . push ( s [ i ] ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) document . write ( ans [ i ] + " " ) ; document . write ( ans [ n - 1 ] ) ; } let n = 5 ; lexNumbers ( n ) ;

Index/key variables: i, sum, x
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function minimumCost ( binary , n , a , b ) { var groupOfZeros = [ ] ; var len = 0 , i = 0 ; var increment_need = true ; while ( i < n ) { increment_need = true ; while ( i < n && binary [ i ] == 0 ) { len ++ ; i ++ ; increment_need = false ; } if ( increment_need == true ) { i ++ ; } if ( len != 0 ) { groupOfZeros . push ( len ) ; } len = 0 ; } groupOfZeros . sort ( ( a , b ) => a - b ) ; i = 0 ; var found_ones = false ; var NumOfOnes = 0 ; while ( i < n ) { found_ones = false ; while ( i < n && binary [ i ] == 1 ) { i ++ ; found_ones = true ; } if ( found_ones == false ) i ++ ; else NumOfOnes ++ ; } var ans = 1000000000 ; for ( var i = 0 ; i < n ; i ++ ) { var curr = 0 , totalOnes = NumOfOnes ; if ( i == 0 ) { curr = totalOnes * a ; } else { var mark = i , num_of_changes = 0 ; groupOfZeros . forEach ( x => { if ( mark >= x ) { totalOnes -- ; mark -= x ; num_of_changes += x ; } } ) ; curr = ( num_of_changes * b ) + ( totalOnes * a ) ; } ans = Math . min ( ans , curr ) ; } document . write ( ans ) ; } var arr = [ 1 , 1 , 1 , 0 , 1 , 1 ] ; var N = arr . length ; var X = 10 , Y = 4 ; minimumCost ( arr , N , X , Y ) ;

Index/key variables: i
Accumulator variables: NumOfOnes, i, len, mark, num_of_changes, totalOnes
Iterator variables: i
Boolean variables: found_ones, increment_need
Javascript program:
function isSortedparitions ( arr , i , j ) { for ( var k = i + 1 ; k <= j ; k ++ ) { if ( arr [ k ] < arr [ k - 1 ] ) { return 0 ; } } return 1 ; } function partitionsArr ( arr , i , j ) { if ( i >= j ) return 1 ; var flag = isSortedparitions ( arr , i , j ) ; if ( flag ) { return ( j - i + 1 ) ; } var mid = parseInt ( ( i + j ) / 2 ) ; var X = partitionsArr ( arr , i , mid ) ; var Y = partitionsArr ( arr , mid + 1 , j ) ; return Math . max ( X , Y ) ; } var arr = [ 11 , 12 , 1 , 2 , 13 , 14 , 3 , 4 ] ; var N = arr . length ; document . write ( partitionsArr ( arr , 0 , N - 1 ) ) ;

Index/key variables: k
Accumulator variables: k
Iterator variables: k
Javascript program:
function checkIfPossibleMerge ( A , B , N ) { let i = 0 ; let j = 0 ; let prev = - 1 ; let flag = true ; while ( i < N && j < N ) { if ( A [ i ] < B [ j ] && prev != 0 ) { prev = 0 ; i ++ ; } else if ( B [ j ] < A [ i ] && prev != 1 ) { prev = 1 ; j ++ ; } else if ( A [ i ] == B [ j ] ) { if ( prev != 1 ) { prev = 1 ; j ++ ; } else { prev = 0 ; i ++ ; } } else { flag = false ; break ; } } return flag ; } let A = [ 3 , 5 , 8 ] ; let B = [ 2 , 4 , 6 ] ; let N = A . length ; if ( checkIfPossibleMerge ( A , B , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Boolean variables: flag
Javascript program:
function minimum_possible_sum ( arr , n , k ) { if ( n == 0 ) { return 0 ; } if ( n == 1 ) { return arr [ 0 ] ; } for ( let i = 0 ; i < k ; i ++ ) { let smallest_element = arr [ 0 ] ; let smallest_pos = 0 ; let largest_element = arr [ 0 ] ; let largest_pos = 0 ; for ( let j = 1 ; j < n ; j ++ ) { if ( arr [ j ] >= largest_element ) { largest_element = arr [ j ] ; largest_pos = j ; } if ( arr [ j ] < smallest_element ) { smallest_element = arr [ j ] ; smallest_pos = j ; } } let a = smallest_element * 2 ; let b = largest_element / 2 ; if ( a + b < smallest_element + largest_element ) { arr [ smallest_pos ] = a ; arr [ largest_pos ] = b ; } } let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { ans += arr [ i ] ; } return ans ; } let arr = [ 50 , 1 , 100 , 100 , 1 ] ; let K = 2 ; let n = arr . length ; document . write ( minimum_possible_sum ( arr , n , K ) ) ;

Index/key variables: i, j, largest_pos, smallest_pos
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function maxSum ( n , a , l , q ) { let v = [ ] ; let d = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { d [ i ] = 0 ; } for ( let i = 0 ; i < q ; i ++ ) { for ( let x = l [ i ] [ 0 ] ; x <= l [ i ] [ 1 ] ; x ++ ) { if ( d [ x ] == 0 ) { d [ x ] = 1 ; } } } let st = new Set ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( d [ i ] == 0 ) { v . push ( a [ i ] ) ; st . add ( i ) ; } } v . sort ( function ( a , b ) { return b - a ; } ) ; let c = 0 ; for ( let it of st . values ( ) ) { a [ it ] = v ; c ++ ; } let pref_sum = 0 ; let temp_sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { temp_sum += a [ i ] ; pref_sum += temp_sum ; } return pref_sum ; } let arr = [ - 8 , 4 , - 2 , - 6 , 4 , 7 , 1 ] ; let N = arr . length ; let q = [ [ 0 , 0 ] , [ 4 , 5 ] ] ; let queries = q . length ; document . write ( maxSum ( N , arr , q , queries ) ) ;

Index/key variables: i, it, x
Accumulator variables: c, i, pref_sum, temp_sum, x
Iterator variables: i, it, x