dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let N = 3 ; function getGreatestSum ( a ) { let prev_max = 0 ; for ( let j = 0 ; j < N ; j ++ ) if ( prev_max < a [ N - 1 ] [ j ] ) prev_max = a [ N - 1 ] [ j ] ; let sum = prev_max ; for ( let i = N - 2 ; i >= 0 ; i -- ) { let curr_max = - 2147483648 ; for ( let j = 0 ; j < N ; j ++ ) if ( prev_max > a [ i ] [ j ] && a [ i ] [ j ] > curr_max ) curr_max = a [ i ] [ j ] ; if ( curr_max == - 2147483648 ) return - 1 ; prev_max = curr_max ; sum += prev_max ; } return sum ; } let a = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; document . write ( getGreatestSum ( a ) + " " ) ; let b = [ [ 4 , 5 , 6 ] , [ 4 , 5 , 6 ] , [ 4 , 5 , 6 ] ] ; document . write ( getGreatestSum ( b ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function occurrenceDays ( n , firstday ) { let days = [ " " , " " , " " , " " , " " , " " , " " ] ; let count = [ ] ; for ( let i = 0 ; i < 7 ; i ++ ) count [ i ] = 4 ; let pos = 0 ; for ( let i = 0 ; i < 7 ; i ++ ) { if ( firstday == days [ i ] ) { pos = i ; break ; } } let inc = n - 28 ; for ( let i = pos ; i < pos + inc ; i ++ ) { if ( i > 6 ) count [ i % 7 ] = 5 ; else count [ i ] = 5 ; } for ( let i = 0 ; i < 7 ; i ++ ) { document . write ( days [ i ] + " " + count [ i ] + " " ) ; } } let n = 31 ; let firstday = " " ; occurrenceDays ( n , firstday ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findElement ( n , k ) { let ans = n ; let left = 1 ; let right = ( Math . pow ( 2 , n ) - 1 ) ; while ( true ) { let mid = ( left + right ) / 2 ; if ( k == mid ) { document . write ( ans ) ; break ; } ans -- ; if ( k < mid ) { right = mid - 1 ; } else { left = mid + 1 ; } } } let n = 4 , k = 8 ; findElement ( n , k ) ;

Accumulator variables: ans
Javascript program:
class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } ; function push ( head_ref , new_data ) { var new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } function firstCommon ( head1 , head2 ) { for ( ; head1 != null ; head1 = head1 . next ) for ( var p = head2 ; p != null ; p = p . next ) if ( p . data == head1 . data ) return head1 . data ; return 0 ; } var head1 = null ; head1 = push ( head1 , 20 ) ; head1 = push ( head1 , 5 ) ; head1 = push ( head1 , 15 ) ; head1 = push ( head1 , 10 ) ; var head2 = null ; head2 = push ( head2 , 10 ) ; head2 = push ( head2 , 2 ) ; head2 = push ( head2 , 15 ) ; head2 = push ( head2 , 8 ) ; document . write ( firstCommon ( head1 , head2 ) ) ;

Iterator variables: p
Class/struct names: Node
Javascript program:
function countMaxSumPairs ( a , n ) { let first = Number . MIN_VALUE , second = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] > first ) { second = first ; first = a [ i ] ; } else if ( a [ i ] > second && a [ i ] != first ) second = a [ i ] ; } let cnt1 = 0 , cnt2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == first ) cnt1 ++ ; if ( a [ i ] == second ) cnt2 ++ ; } if ( cnt1 == 1 ) return cnt2 ; if ( cnt1 > 1 ) return cnt1 * ( cnt1 - 1 ) / 2 ; return 0 ; } function findMaxSumProbability ( a , n ) { let total = n * ( n - 1 ) / 2 ; let max_sum_pairs = countMaxSumPairs ( a , n ) ; return max_sum_pairs / total ; } let a = [ 1 , 2 , 2 , 3 ] ; let n = a . length ; ; document . write ( findMaxSumProbability ( a , n ) ) ;

Index/key variables: i
Accumulator variables: cnt1, cnt2, i
Iterator variables: i
Javascript program:
for ( var i = k - 1 ; i <= n ; i ++ ) best = Math . min ( best , Math . max ( partition ( arr , i , k - 1 ) , sum ( arr , i , n - 1 ) ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findS ( s ) { var sum = 0 ; for ( n = 1 ; sum < s ; n ++ ) { sum += n ; if ( sum == s ) return n ; } return - 1 ; } var s = 15 ; var n = findS ( s ) ; if ( n == - 1 ) document . write ( " " ) ; else document . write ( n ) ;

Accumulator variables: n, sum
Iterator variables: n
Javascript program:
let count_crossline = 0 ; function merge ( arr , l , m , r ) { let i , j , k ; let n1 = m - l + 1 ; let n2 = r - m ; let L = [ ] ; let R = [ ] ; for ( i = 0 ; i < n1 ; i ++ ) { L [ i ] = arr [ l + i ] ; } for ( j = 0 ; j < n2 ; j ++ ) { R [ j ] = arr [ m + 1 + j ] ; } while ( i < n1 && j < n2 ) { if ( L [ i ] <= R [ j ] ) { arr [ k ] = L [ i ] ; i ++ ; } else { arr [ k ] = R [ j ] ; count_crossline += ( n1 - i ) ; j ++ ; } k ++ ; } while ( i < n1 ) { arr [ k ] = L [ i ] ; i ++ ; k ++ ; } while ( j < n2 ) { arr [ k ] = R [ j ] ; j ++ ; k ++ ; } } function mergeSort ( arr , l , r ) { if ( l < r ) { let m = l + Math . floor ( ( r - l ) / 2 ) ; mergeSort ( arr , l , m ) ; mergeSort ( arr , m + 1 , r ) ; merge ( arr , l , m , r ) ; } } function countCrossLine ( arr , n ) { mergeSort ( arr , 0 , n - 1 ) ; document . write ( count_crossline ) ; } let arr = [ 12 , 11 , 13 , 5 , 6 , 7 ] ; let n = arr . length ; countCrossLine ( arr , n ) ;

Index/key variables: i, j, k
Accumulator variables: count_crossline, i, j, k
Iterator variables: i, j
Javascript program:
function getCount ( arr , n , num1 , num2 ) { let i = 0 ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == num1 ) break ; if ( i >= n - 1 ) return 0 ; let j ; for ( j = n - 1 ; j >= i + 1 ; j -- ) if ( arr [ j ] == num2 ) break ; if ( j == i ) return 0 ; return ( j - i - 1 ) ; } let arr = [ 3 , 5 , 7 , 6 , 4 , 9 , 12 , 4 , 8 ] ; let n = arr . length ; let num1 = 5 , num2 = 4 ; document . write ( getCount ( arr , n , num1 , num2 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let ROW = 3 ; let COL = 5 ; function minTotalDistance ( grid ) { if ( ROW == 0 COL == 0 ) return 0 ; let vertical = [ ] ; let horizontal = [ ] ; for ( let i = 0 ; i < ROW ; i ++ ) { for ( let j = 0 ; j < COL ; j ++ ) { if ( grid [ i ] [ j ] == 1 ) { vertical . push ( i ) ; horizontal . push ( j ) ; } } } ( vertical ) . sort ( function ( a , b ) { return a - b ; } ) ; ( horizontal ) . sort ( function ( a , b ) { return a - b ; } ) ; let size = vertical . length / 2 ; let x = vertical [ size ] ; let y = horizontal [ size ] ; let distance = 0 ; for ( let i = 0 ; i < ROW ; i ++ ) for ( let j = 0 ; j < COL ; j ++ ) if ( grid [ i ] [ j ] == 1 ) distance += Math . abs ( x - i ) + Math . abs ( y - j ) ; return distance ; } let grid = [ [ 1 , 0 , 1 , 0 , 1 ] , [ 0 , 1 , 0 , 0 , 0 ] , [ 0 , 1 , 1 , 0 , 0 ] ] ; document . write ( minTotalDistance ( grid ) ) ;

Index/key variables: i, j, size
Accumulator variables: distance, i, j
Iterator variables: i, j
Javascript program:
function sumOfDigit ( K ) { let sod = 0 ; while ( K ) { sod += K % 10 ; K /= 10 ; } return sod ; } function totalNumbersWithSpecificDifference ( N , diff ) { let low = 1 ; let high = N ; while ( low <= high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( mid - sumOfDigit ( mid ) < diff ) low = mid + 1 ; else high = mid - 1 ; } return ( N - high ) ; } let N = 13 ; let diff = 2 ; document . write ( totalNumbersWithSpecificDifference ( N , diff ) ) ;

Accumulator variables: K, sod
Javascript program:
function getRandom ( x , y ) { return Math . floor ( x + Math . floor ( Math . random ( ) * 10 ) % ( y - x + 1 ) ) ; } function randomizedBinarySearch ( arr , l , r , x ) { while ( l <= r ) { let m = getRandom ( l , r ) ; if ( arr [ m ] == x ) return m ; if ( arr [ m ] < x ) l = m + 1 ; else r = m - 1 ; } return - 1 ; } let arr = [ 2 , 3 , 4 , 10 , 40 ] ; let n = arr . length ; let x = 10 ; let result = randomizedBinarySearch ( arr , 0 , n - 1 , x ) ; if ( result == - 1 ) document . write ( " " ) ; else document . write ( " " , result ) ;

Index/key variables: m
Javascript program:
function countBuildings ( arr , n ) { let count = 1 ; let curr_max = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > curr_max arr [ i ] == curr_max ) { count ++ ; curr_max = arr [ i ] ; } } return count ; } let arr = [ 7 , 4 , 8 , 2 , 9 ] ; let n = arr . length ; document . write ( countBuildings ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
function findExtra ( arr1 , arr2 , n ) { for ( let i = 0 ; i < n ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ; return n ; } let arr1 = [ 2 , 4 , 6 , 8 , 10 , 12 , 13 ] ; let arr2 = [ 2 , 4 , 6 , 8 , 10 , 12 ] ; let n = arr2 . length ; document . write ( findExtra ( arr1 , arr2 , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function findExtra ( arr1 , arr2 , n ) { let index = n ; let left = 0 , right = n - 1 ; while ( left <= right ) { let mid = Math . floor ( ( left + right ) / 2 ) ; if ( arr2 [ mid ] == arr1 [ mid ] ) left = mid + 1 ; else { index = mid ; right = mid - 1 ; } } return index ; } let arr1 = [ 2 , 4 , 6 , 8 , 10 , 12 , 13 ] ; let arr2 = [ 2 , 4 , 6 , 8 , 10 , 12 ] ; let n = arr2 . length ; document . write ( findExtra ( arr1 , arr2 , n ) ) ;

Index/key variables: mid
Javascript program:
function computeCost ( arr , N , X ) { let cost = 0 ; for ( let i = 0 ; i < N ; i ++ ) cost += Math . abs ( arr [ i ] - X ) ; return cost ; } function minCostToMakeElementEqual ( arr , N ) { let low , high ; low = high = arr [ 0 ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( low > arr [ i ] ) low = arr [ i ] ; if ( high < arr [ i ] ) high = arr [ i ] ; } while ( ( high - low ) > 2 ) { let mid1 = low + ( high - low ) / 3 ; let mid2 = high - ( high - low ) / 3 ; let cost1 = computeCost ( arr , N , mid1 ) ; let cost2 = computeCost ( arr , N , mid2 ) ; if ( cost1 < cost2 ) high = mid2 ; else low = mid1 ; } return Math . round ( computeCost ( arr , N , ( low + high ) / 2 ) ) ; } let arr = [ 1 , 100 , 101 ] ; let N = arr . length ; document . write ( minCostToMakeElementEqual ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: cost, i
Iterator variables: i
Javascript program:
function minJumps ( w , l , n ) { if ( n == 1 ) { document . write ( 0 ) ; return ; } var ans = 0 ; var i ; var pos = new Map ( ) ; var jump = new Map ( ) ; var filled = new Map ( ) ; var a = new Array ( n ) ; for ( i = 0 ; i < n ; i ++ ) { pos . set ( w [ i ] , i ) ; filled . set ( i , true ) ; jump . set ( w [ i ] , l [ i ] ) ; a [ i ] = w [ i ] ; } a = a . sort ( function ( p , q ) { return p - q ; } ) ; for ( curr = 1 ; curr < n ; curr ++ ) { var currElementPos = pos . get ( a [ curr ] ) ; var prevElementPos = pos . get ( a [ curr - 1 ] ) ; if ( currElementPos > prevElementPos ) continue ; while ( currElementPos <= prevElementPos filled [ currElementPos ] ) { currElementPos += jump . get ( a [ curr ] ) ; ans += 1 ; } pos . set ( a [ curr ] , currElementPos ) ; filled . set ( currElementPos , true ) ; } document . write ( ans ) ; } var W = [ 2 , 1 , 4 , 3 ] ; var L = [ 4 , 1 , 2 , 4 ] ; var N = W . length ; minJumps ( W , L , N ) ;

Index/key variables: curr, currElementPos, i
Accumulator variables: ans, curr, currElementPos, i
Iterator variables: curr, i
Javascript program:
function check ( arr , n ) { for ( var i = 1 ; i < n ; i ++ ) { if ( arr [ i - 1 ] >= ( i - 1 ) ) { var p = arr [ i - 1 ] - ( i - 1 ) ; arr [ i ] += p ; arr [ i - 1 ] -= p ; } } for ( var i = 1 ; i < n ; i ++ ) { if ( arr [ i ] <= arr [ i - 1 ] ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } var arr = [ 1 , 5 , 2 , 7 , 6 ] ; var N = arr . length ; check ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function keyFunc ( n ) { let rev = 0 ; while ( n > 0 ) { rev = rev << 1 ; if ( n & 1 == 1 ) rev = rev ^ 1 ; n = n >> 1 ; } return rev ; } function getNew ( arr ) { let ans = [ ] ; for ( let i of arr ) ans . push ( [ keyFunc ( i ) , i ] ) ; return ans ; } function getArr ( arr ) { let ans = [ ] ; for ( let i of arr ) ans . push ( i [ 1 ] ) ; return ans ; } function sortArray ( arr ) { let newArr = getNew ( arr ) ; newArr . sort ( ) ; arr = getArr ( newArr ) ; let n = arr . length ; document . write ( " " ) ; for ( let i = 0 ; i < n - 1 ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( arr [ n - 1 ] + " " ) ; } let arr = [ 43 , 52 , 61 , 41 ] ; sortArray ( arr ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minimumSize ( arr , N , K ) { ( arr ) . sort ( function ( a , b ) { return a - b ; } ) ; reverse ( arr ) ; if ( count ( arr , 0 ) == N ) document . write ( 0 ) ; else if ( K >= N ) document . write ( 1 ) ; else document . write ( arr [ K ] ) ; } function reverse ( a ) { let i , k , t ; let n = a . length ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } } function count ( a , n ) { let freq = 0 ; for ( let i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] == n ) freq ++ ; } return freq ; } let arr = [ 2 , 4 , 8 , 2 ] ; let K = 2 ; let N = arr . length ; minimumSize ( arr , N , K ) ;

Index/key variables: K, i
Accumulator variables: freq, i
Iterator variables: i
Javascript program:
function isPossibleToSort ( arr , N ) { var idx = - 1 ; var i ; for ( i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == 1 && arr [ i - 1 ] == 1 ) { idx = i ; break ; } } if ( idx == - 1 ) { document . write ( " " ) ; return ; } for ( i = idx + 1 ; i < N ; i ++ ) { if ( arr [ i ] == 0 && arr [ i - 1 ] == 0 ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } var arr = [ 1 , 0 , 1 , 0 , 1 , 1 , 0 ] ; var N = arr . length ; isPossibleToSort ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxConsecutiveRopes ( ropes , N ) { let curSize = 0 ; ropes . sort ( ( a , b ) => a - b ) for ( let i = 0 ; i < N ; i ++ ) { if ( ropes [ i ] <= curSize + 1 ) { curSize = curSize + ropes [ i ] ; } else break ; } return curSize ; } let N = 5 ; let ropes = [ 1 , 2 , 7 , 1 , 1 ] ; document . write ( maxConsecutiveRopes ( ropes , N ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxRanges ( arr , N ) { arr . sort ( ( a , b ) => { return b [ 0 ] - a [ 0 ] } ) let count = 1 ; let prev = arr [ 0 ] ; for ( let i = 1 ; i < N ; i ++ ) { let last = arr [ i - 1 ] ; let current = arr [ i ] ; if ( last [ 0 ] == current [ 0 ] && last [ 1 ] == current [ 1 ] && current [ 1 ] == current [ 0 ] ) { continue ; } let start = Math . max ( prev [ 0 ] , current [ 0 ] - 1 ) ; let end = Math . max ( prev [ 1 ] , current [ 1 ] ) ; if ( ( end - start ) > 0 ) { prev [ 0 ] = 1 + start ; prev [ 1 ] = end ; count ++ ; } } return count ; } let range = [ [ 1 , 4 ] , [ 4 , 4 ] , [ 2 , 2 ] , [ 3 , 4 ] , [ 1 , 1 ] ] ; let N = range . length ; document . write ( maxRanges ( range , N ) ) ;

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Javascript program:
var i , start , end ; function adjust ( S ) { var N = S . length ; start = i - 1 ; while ( i < N && S [ i ] < S [ i - 1 ] ) { i ++ ; } end = i - 1 ; if ( start <= 0 && i >= N ) return true ; if ( start >= 1 && i <= N ) { return S [ end ] >= S [ start - 1 ] && S [ start ] <= S [ i ] ; } if ( start >= 1 ) { return S [ end ] >= S [ start - 1 ] ; } if ( i < N ) { return S [ start ] <= S [ i ] ; } return false ; } function isPossible ( S , N ) { start = - 1 ; end = - 1 ; var flag = true ; for ( i = 1 ; i < N ; i ++ ) { if ( S [ i ] < S [ i - 1 ] ) { if ( flag ) { if ( adjust ( S ) === false ) { document . write ( - 1 ) ; return ; } flag = false ; } else { document . write ( - 1 ) ; return ; } } } if ( start === - 1 ) { start = end = 1 ; } document . write ( start + " " + end + " " ) ; } var S = " " ; var N = S . length ; isPossible ( S , N ) ;

Index/key variables: end, i, start
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Javascript program:
function maximumSum ( arr , S , N , K ) { var ans = 0 ; var i ; arr . sort ( ( a , b ) => b - a ) ; for ( i = 0 ; i < K ; i ++ ) ans += arr [ i ] ; S . sort ( ) ; for ( i = 0 ; i < K ; i ++ ) { if ( S [ i ] == 1 ) ans += arr [ i ] ; S [ i ] -= 1 ; } var counter = K - 1 ; for ( i = 0 ; i < K ; i ++ ) { counter = counter + S [ i ] ; if ( S [ i ] != 0 ) ans += arr [ counter ] ; } return ans ; } var arr = [ 1 , 13 , 7 , 17 ] ; var S = [ 1 , 3 ] ; var N = arr . length ; var K = S . length ; document . write ( maximumSum ( arr , S , N , K ) ) ;

Index/key variables: counter, i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function binaryToDecimal ( n ) { let num = n ; let dec_value = 0 ; let base = 1 ; let len = num . length ; for ( let i = len - 1 ; i >= 0 ; i -- ) { if ( num [ i ] == ' ' ) dec_value += base ; base = base * 2 ; } return dec_value ; } function decimalToBinary ( n ) { let binstr = " " ; while ( n > 0 ) { binstr += String . fromCharCode ( n % 2 + 48 ) ; n = Math . floor ( n / 2 ) ; } return binstr ; } function reversedBinaryDecimal ( N ) { let decimal_to_binar = decimalToBinary ( N ) ; let binary_to_decimal = binaryToDecimal ( decimal_to_binar ) ; return binary_to_decimal ; } function printSortedArray ( arr , size ) { arr . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < size ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) } function modifyArray ( arr , size ) { for ( let i = 0 ; i < size ; i ++ ) { arr [ i ] = reversedBinaryDecimal ( arr [ i ] ) ; } printSortedArray ( arr , size ) ; } let arr = [ 98 , 43 , 66 , 83 ] ; let n = arr . length ; modifyArray ( arr , n ) ;

Index/key variables: i
Accumulator variables: binstr, dec_value, i
Iterator variables: i
Javascript program:
function isSortedArray ( arr , n ) { var l = 0 var r = ( n - 1 ) while ( ( l + 1 ) < r ) { if ( arr [ l ] >= Math . max ( arr [ l + 1 ] , arr [ r - 1 ] ) && arr [ r ] >= Math . max ( arr [ r - 1 ] , arr [ l + 1 ] ) ) { l += 1 r -= 1 } else return false } return true } var arr = [ 4 , 3 , 1 , 2 , 5 ] var N = arr . length if ( isSortedArray ( arr , N ) ) console . log ( " " ) else console . log ( " " )

Index/key variables: l, r
Accumulator variables: l, r
Javascript program:
function maxLenSubset ( a , n ) { a . sort ( function ( a , b ) { return a - b ; } ) let index = 0 , maxlen = - 1 ; let i = 0 ; while ( i < n ) { let j = i ; let len = 1 ; while ( j < n - 1 ) { if ( 2 * a [ j ] >= a [ j + 1 ] ) { len ++ ; } else break ; j ++ ; } if ( maxlen < len ) { maxlen = len ; index = i ; } j ++ ; i = j ; } i = index ; while ( maxlen > 0 ) { document . write ( a [ i ] + " " ) maxlen -- ; i ++ ; } } let a = [ 3 , 1 , 5 , 11 ] ; let n = a . length maxLenSubset ( a , n )

Index/key variables: i, j
Accumulator variables: i, j, len, maxlen
Javascript program:
function canReduceArray ( arr , N , K ) { arr . sort ( ) ; let b = Array ( N ) . fill ( 0 ) ; let j = N ; for ( let i = 0 ; i < N ; i ++ ) { b [ j - 1 ] = arr [ i ] ; j = j - 1 ; } for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] - arr [ i + 1 ] > K ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let arr = [ 2 , 1 , 1 , 3 ] ; let N = arr . length ; let K = 1 ; canReduceArray ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function mergeStrings ( s1 , s2 ) { var len1 = s1 . length ; var len2 = s2 . length ; var pntr1 = 0 ; var pntr2 = 0 ; var ans = " " ; while ( pntr1 < len1 && pntr2 < len2 ) { if ( s1 [ pntr1 ] < s2 [ pntr2 ] ) { ans += s1 [ pntr1 ] ; pntr1 ++ ; } else { ans += s2 [ pntr2 ] ; pntr2 ++ ; } } if ( pntr1 < len1 ) { ans += s1 . substr ( pntr1 , len1 ) ; } if ( pntr2 < len2 ) { ans += s2 . substr ( pntr2 , len2 ) ; } document . write ( ans ) ; } var S1 = " " ; var S2 = " " ; mergeStrings ( S1 , S2 ) ;

Index/key variables: pntr1, pntr2
Accumulator variables: ans, pntr1, pntr2
Javascript program:
function sortStr ( str ) { var S = str . split ( ' ' ) ; var N = S . length ; var temp = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { if ( S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' ) temp . push ( S [ i ] ) ; } if ( temp . length != 0 ) temp . sort ( ) ; var ptr = 0 ; for ( var i = 0 ; i < N ; i ++ ) { if ( S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' && S [ i ] != ' ' ) S [ i ] = temp [ ptr ++ ] ; } var str = " " ; for ( var i = 0 ; i < S . length ; i ++ ) str += S [ i ] ; document . write ( str ) ; } var S = " " ; sortStr ( S ) ;

Index/key variables: i
Accumulator variables: i, ptr, str
Iterator variables: i
Javascript program:
function upper_bound ( arr , key ) { let l = - 1 , r = arr . length ; while ( l + 1 < r ) { let m = ( l + r ) >>> 1 ; if ( arr [ m ] <= key ) l = m ; else r = m ; } return l + 1 ; } function countPairs ( arr , n , k ) { arr . sort ( ) ; let ans = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) { let high = upper_bound ( arr , k * arr [ i ] ) ; ans += high - i - 1 ; } document . write ( ans ) ; } let arr = [ 2 , 3 , 9 , 5 ] ; let n = arr . length ; let k = 2 ; countPairs ( arr , n , k ) ;

Index/key variables: i, m
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function findXOR ( mat , K ) { let N = mat . length ; let M = mat [ 0 ] . length ; let digXOR = [ ] ; for ( let l = 1 ; l <= ( N + M - 1 ) ; l ++ ) { let s_col = Math . max ( 0 , l - N ) ; let count = Math . min ( l , ( M - s_col ) , N ) ; let currXOR = 0 ; for ( let j = 0 ; j < count ; j ++ ) { currXOR = ( currXOR ^ mat [ Math . min ( N , l ) - j - 1 ] [ s_col + j ] ) ; } digXOR . push ( currXOR ) ; } digXOR . sort ( ( a , b ) => a - b ) ; document . write ( digXOR [ N + M - 1 - K ] ) ; } let mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; let K = 3 ; findXOR ( mat , K ) ;

Accumulator variables: j, l
Iterator variables: j, l
Javascript program:
function findMaxNumbers ( arr , n , k ) { arr . sort ( ) ; let cnt = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let opr = Math . ceil ( Math . log2 ( arr [ i ] ) ) ; k -= opr ; if ( k < 0 ) { break ; } cnt ++ ; } document . write ( cnt ) ; } let arr = [ 5 , 8 , 4 , 7 ] ; let N = arr . length ; let K = 5 ; findMaxNumbers ( arr , N , K ) ;

Index/key variables: i
Accumulator variables: cnt, i, k
Iterator variables: i
Javascript program:
function meanOfRemainingElements ( arr , N , K ) { arr . sort ( function ( a , b ) { return a - b } ) ; let kthPercent = Math . floor ( ( N * K ) / 100 ) ; let sum = 0 ; for ( let i = 0 ; i < N ; i ++ ) if ( i >= kthPercent && i < ( N - kthPercent ) ) sum += arr [ i ] ; let mean = sum / ( N - 2 * kthPercent ) ; document . write ( mean . toFixed ( 5 ) ) ; } let arr = [ 6 , 2 , 7 , 5 , 1 , 2 , 0 , 3 , 10 , 2 , 5 , 0 , 5 , 5 , 0 , 8 , 7 , 6 , 8 , 0 ] ; let arr_size = arr . length ; let K = 5 ; meanOfRemainingElements ( arr , arr_size , K ) ;

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Javascript program:
function minOperation ( a , N ) { var totOps = 0 ; for ( i = 0 ; i < N - 1 ; i ++ ) { totOps += Math . abs ( a [ i ] - a [ i + 1 ] ) ; } var maxOps = Math . max ( Math . abs ( a [ 0 ] - a [ 1 ] ) , Math . abs ( a [ N - 1 ] - a [ N - 2 ] ) ) ; for ( i = 1 ; i < N - 1 ; i ++ ) { maxOps = Math . max ( maxOps , Math . abs ( a [ i ] - a [ i - 1 ] ) + Math . abs ( a [ i ] - a [ i + 1 ] ) - Math . abs ( a [ i - 1 ] - a [ i + 1 ] ) ) ; } document . write ( totOps - maxOps ) ; } var arr = [ 1 , - 1 , 0 , 1 , 1 ] ; var N = arr . length ; minOperation ( arr , N ) ;

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