dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function findSubArray ( arr , n ) { let start , end , min_sum = Number . MAX_SAFE_INTEGER ; for ( let i = 0 ; i < n ; i ++ ) { let curr_sum = arr [ i ] ; if ( min_sum > Math . abs ( curr_sum ) ) { min_sum = Math . abs ( curr_sum ) ; start = i ; end = i ; } for ( let j = i + 1 ; j < n ; j ++ ) { curr_sum = curr_sum + arr [ j ] ; if ( min_sum > Math . abs ( curr_sum ) ) { min_sum = Math . abs ( curr_sum ) ; start = i ; end = j ; } } } let p = [ start , end ] ; return p ; } let arr = [ 2 , - 5 , 4 , - 6 , - 3 ] ; let n = arr . length ; let point = findSubArray ( arr , n ) ; document . write ( " " ) ; document . write ( point [ 0 ] + " " + point [ 1 ] ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function findMinimum ( arr , n , k ) { let res = 0 ; for ( let i = 0 ; i < n ; i ++ ) { res += arr [ i ] ; n = n - k ; } return res ; } function findMaximum ( arr , n , k ) { let res = 0 , index = 0 ; for ( let i = n - 1 ; i >= index ; i -- ) { res += arr [ i ] ; index += k ; } return res ; } let arr = [ 3 , 2 , 1 , 4 ] ; let n = arr . length ; let k = 2 ; arr . sort ( function ( a , b ) { return a - b ; } ) ; document . write ( findMinimum ( arr , n , k ) + " " + findMaximum ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, index, res
Iterator variables: i
Javascript program:
function printInSortedOrder ( arr , n ) { let index = new Array ( n ) ; let i , j , min ; for ( i = 0 ; i < n ; i ++ ) { index [ i ] = i ; } for ( i = 0 ; i < n - 1 ; i ++ ) { min = i ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ index [ min ] ] > ( arr [ index [ j ] ] ) ) { min = j ; } } if ( min != i ) { let temp = index [ min ] ; index [ min ] = index [ i ] ; index [ i ] = temp ; } } for ( i = 0 ; i < n ; i ++ ) { document . write ( arr [ index [ i ] ] + " " ) ; } } let arr = [ " " , " " , " " , " " ] ; let n = 4 ; printInSortedOrder ( arr , n ) ;

Index/key variables: i, j, min
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxLevel ( boxes , n ) { boxes . sort ( ) ; let prev_width = boxes [ 0 ] ; let prev_count = 1 ; let curr_count = 0 ; let curr_width = 0 ; for ( let i = 1 ; i < n ; i ++ ) { curr_width += boxes [ i ] ; curr_count += 1 ; if ( curr_width > prev_width && curr_count > prev_count ) { prev_width = curr_width ; prev_count = curr_count ; curr_count = 0 ; curr_width = 0 ; ans ++ ; } } return ans ; } let boxes = [ 10 , 20 , 30 , 50 , 60 , 70 ] ; let n = boxes . length ; document . write ( maxLevel ( boxes , n ) ) ;

Index/key variables: i
Accumulator variables: ans, curr_count, curr_width, i
Iterator variables: i
Javascript program:
const MAX_SIZE = 10 ; function sortArrayUsingCounts ( arr , n ) { let count = new Uint8Array ( MAX_SIZE ) ; for ( let i = 0 ; i < n ; i ++ ) count [ arr [ i ] ] ++ ; let index = 0 ; for ( let i = 0 ; i < MAX_SIZE ; i ++ ) while ( count [ i ] > 0 ) arr [ index ++ ] = i , count [ i ] -- ; } function removeAndPrintResult ( arr , n , ind1 , ind2 = - 1 ) { for ( let i = n - 1 ; i >= 0 ; i -- ) if ( i != ind1 && i != ind2 ) document . write ( arr [ i ] ) ; } function largest3Multiple ( arr , n ) { let sum = arr . reduce ( ( a , b ) => a + b , 0 ) ; if ( sum % 3 == 0 ) return true ; sortArrayUsingCounts ( arr , n ) ; let remainder = sum % 3 ; if ( remainder == 1 ) { let rem_2 = new Array ( 2 ) ; rem_2 [ 0 ] = - 1 , rem_2 [ 1 ] = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 3 == 1 ) { removeAndPrintResult ( arr , n , i ) ; return true ; } if ( arr [ i ] % 3 == 2 ) { if ( rem_2 [ 0 ] == - 1 ) rem_2 [ 0 ] = i ; else if ( rem_2 [ 1 ] == - 1 ) rem_2 [ 1 ] = i ; } } if ( rem_2 [ 0 ] != - 1 && rem_2 [ 1 ] != - 1 ) { removeAndPrintResult ( arr , n , rem_2 [ 0 ] , rem_2 [ 1 ] ) ; return true ; } } else if ( remainder == 2 ) { let rem_1 = new Array ( 2 ) ; rem_1 [ 0 ] = - 1 , rem_1 [ 1 ] = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 3 == 2 ) { removeAndPrintResult ( arr , n , i ) ; return true ; } if ( arr [ i ] % 3 == 1 ) { if ( rem_1 [ 0 ] == - 1 ) rem_1 [ 0 ] = i ; else if ( rem_1 [ 1 ] == - 1 ) rem_1 [ 1 ] = i ; } } if ( rem_1 [ 0 ] != - 1 && rem_1 [ 1 ] != - 1 ) { removeAndPrintResult ( arr , n , rem_1 [ 0 ] , rem_1 [ 1 ] ) ; return true ; } } document . write ( " " ) ; return false ; } let arr = [ 4 , 4 , 1 , 1 , 1 , 3 ] ; let n = arr . length ; largest3Multiple ( arr , n ) ;

Index/key variables: i
Accumulator variables: i, index
Iterator variables: i
Javascript program:
function merge ( arr , temp , left , mid , right ) { let inv_count = 0 ; let i = left ; let j = mid ; let k = left ; while ( ( i <= mid - 1 ) && ( j <= right ) ) { if ( arr [ i ] <= arr [ j ] ) { temp [ k ++ ] = arr [ i ++ ] ; } else { temp [ k ++ ] = arr [ j ++ ] ; inv_count = inv_count + ( mid - i ) ; } } while ( i <= mid - 1 ) { temp [ k ++ ] = arr [ i ++ ] ; } while ( j <= right ) { temp [ k ++ ] = arr [ j ++ ] ; } for ( i = left ; i <= right ; i ++ ) { arr [ i ] = temp [ i ] ; } return inv_count ; } function _mergeSort ( arr , temp , left , right ) { let mid , inv_count = 0 ; if ( right > left ) { mid = ( right + left ) / 2 ; inv_count = _mergeSort ( arr , temp , left , mid ) ; inv_count += _mergeSort ( arr , temp , mid + 1 , right ) ; inv_count += merge ( arr , temp , left , mid + 1 , right ) ; } return inv_count ; } function mergeSort ( arr , array_size ) { let temp = Array . from ( { length : array_size } , ( _ , i ) => 0 ) ; return _mergeSort ( arr , temp , 0 , array_size - 1 ) ; } function minSwapToReachArr ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] - 1 ) - i > 2 ) { return - 1 ; } } let numOfInversion = mergeSort ( arr , N ) ; return numOfInversion ; } let arr = [ 1 , 2 , 5 , 3 , 4 ] ; let N = arr . length ; let res = minSwapToReachArr ( arr , N ) ; document . write ( res == - 1 ? " " : res ) ;

Index/key variables: i, j
Accumulator variables: i, inv_count, j, k
Iterator variables: i
Javascript program:
function twoWaySort ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) arr [ i ] *= - 1 ; arr . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < n ; i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ; } let arr = [ 1 , 3 , 2 , 7 , 5 , 4 ] ; let n = arr . length ; twoWaySort ( arr , 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 printArr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; } function compare ( a , b ) { if ( a % 2 == 0 && b % 2 == 0 && a < b ) return - 1 ; if ( a % 2 != 0 && b % 2 != 0 && b > a ) return 1 ; if ( a % 2 != 0 ) return - 1 ; return 1 ; } var arr = [ 1 , 3 , 2 , 7 , 5 , 4 ] ; var n = arr . length ; arr . sort ( compare ) ; printArr ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function isPossibleTriangle ( arr , N ) { if ( N < 3 ) return false ; arr . sort ( ) ; for ( let i = 0 ; i < N - 2 ; i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ; return false ; } let arr = [ 5 , 4 , 3 , 1 , 2 ] ; let N = arr . length ; if ( isPossibleTriangle ( arr , N ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX = 1000000 ; function ksmallest ( arr , n , k ) { let b = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { b [ arr [ i ] ] = 1 ; } for ( let j = 1 ; j < MAX ; j ++ ) { if ( b [ j ] != 1 ) { k -- ; } if ( k != 1 ) { return j ; } } return Number . MAX_VALUE ; } let k = 1 ; let arr = [ 1 ] ; let n = arr . length ; document . write ( ksmallest ( arr , n , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: i, j
Javascript program:
function mergeTwoHalf ( A , n ) { A . sort ( ( a , b ) => a - b ) ; } var A = [ 2 , 3 , 8 , - 1 , 7 , 10 ] ; var n = A . length ; mergeTwoHalf ( A , n ) ; for ( var i = 0 ; i < n ; i ++ ) document . write ( A [ i ] + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minDiff ( arr , n , k ) { var result = Number . MAX_VALUE ; arr . sort ( ( a , b ) => a - b ) ; for ( i = 0 ; i <= n - k ; i ++ ) result = Math . min ( result , arr [ i + k - 1 ] - arr [ i ] ) ; return result ; } var arr = [ 10 , 100 , 300 , 200 , 1000 , 20 , 30 ] ; var n = arr . length ; var k = 3 ; document . write ( minDiff ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function bitonicGenerator ( arr , n ) { let evenArr = [ ] ; let oddArr = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 != 1 ) { evenArr . push ( arr [ i ] ) ; } else { oddArr . push ( arr [ i ] ) ; } } evenArr . sort ( function ( a , b ) { return a - b ; } ) ; oddArr . sort ( function ( a , b ) { return b - a ; } ) ; let i = 0 ; for ( let j = 0 ; j < evenArr . length ; j ++ ) { arr [ i ++ ] = evenArr [ j ] ; } for ( let j = 0 ; j < oddArr . length ; j ++ ) { arr [ i ++ ] = oddArr [ j ] ; } } let arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ] ; let n = arr . length ; bitonicGenerator ( arr , n ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function merge ( arr , temp , left , mid , right ) { let inv_count = 0 ; let i = left ; let j = mid ; let k = left ; while ( ( i <= mid - 1 ) && ( j <= right ) ) { if ( arr [ i ] <= arr [ j ] ) temp [ k ++ ] = arr [ i ++ ] ; else { temp [ k ++ ] = arr [ j ++ ] ; inv_count = inv_count + ( mid - i ) ; } } while ( i <= mid - 1 ) temp [ k ++ ] = arr [ i ++ ] ; while ( j <= right ) temp [ k ++ ] = arr [ j ++ ] ; for ( i = left ; i <= right ; i ++ ) arr [ i ] = temp [ i ] ; return inv_count ; } function _mergeSort ( arr , temp , left , right ) { let mid , inv_count = 0 ; if ( right > left ) { mid = Math . floor ( ( right + left ) / 2 ) ; inv_count = _mergeSort ( arr , temp , left , mid ) ; inv_count += _mergeSort ( arr , temp , mid + 1 , right ) ; inv_count += merge ( arr , temp , left , mid + 1 , right ) ; } return inv_count ; } function countSwaps ( arr , n ) { let temp = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { temp [ i ] = 0 ; } return _mergeSort ( arr , temp , 0 , n - 1 ) ; } let arr = [ 1 , 20 , 6 , 4 , 5 ] ; let n = arr . length ; document . write ( " " + countSwaps ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, inv_count, j, k
Iterator variables: i
Javascript program:
function findSurpasser ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) { let count = 0 ; for ( let j = i + 1 ; j < n ; j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ; document . write ( count + " " ) ; } } function printArray ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( ) ; } let arr = [ 2 , 7 , 5 , 3 , 0 , 8 , 1 ] ; let n = arr . length ; document . write ( " " + " " ) ; printArray ( arr , n ) ; document . write ( " " ) ; document . write ( " " + " " + " " ) ; findSurpasser ( arr , n ) ;

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Javascript program:
function solve ( arr , n ) { arr . sort ( ) ; let a = 0 , b = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ; else b = b * 10 + arr [ i ] ; } return a + b ; } let arr = [ 6 , 8 , 4 , 5 , 2 , 3 ] ; let n = arr . length ; document . write ( " " + solve ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxProduct ( arr , n ) { if ( n < 3 ) return - 1 ; let max_product = Number . MIN_VALUE ; for ( let i = 0 ; i < n - 2 ; i ++ ) for ( let j = i + 1 ; j < n - 1 ; j ++ ) for ( let k = j + 1 ; k < n ; k ++ ) max_product = Math . max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ; return max_product ; } let arr = [ 10 , 3 , 5 , 6 , 20 ] ; let n = arr . length ; ; let max = maxProduct ( arr , n ) ; if ( max == - 1 ) document . write ( " " ) ; else document . write ( " " + max ) ;

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Javascript program:
function maxProduct ( arr , n ) { if ( n < 3 ) return - 1 ; leftMin = Array . from ( { length : n } , ( _ , i ) => - 1 ) ; rightMin = Array . from ( { length : n } , ( _ , i ) => - 1 ) ; leftMax = Array . from ( { length : n } , ( _ , i ) => - 1 ) ; rightMax = Array . from ( { length : n } , ( _ , i ) => - 1 ) ; var max_product = Number . MIN_VALUE ; var max_sum = arr [ 0 ] ; var min_sum = arr [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) { leftMax [ i ] = max_sum ; if ( arr [ i ] > max_sum ) max_sum = arr [ i ] ; leftMin [ i ] = min_sum ; if ( arr [ i ] < min_sum ) min_sum = arr [ i ] ; } max_sum = arr [ n - 1 ] ; min_sum = arr [ n - 1 ] ; for ( j = n - 2 ; j >= 0 ; j -- ) { rightMax [ j ] = max_sum ; if ( arr [ j ] > max_sum ) max_sum = arr [ j ] ; rightMin [ j ] = min_sum ; if ( arr [ j ] < min_sum ) min_sum = arr [ j ] ; } for ( i = 1 ; i < n - 1 ; i ++ ) { var max1 = Math . max ( arr [ i ] * leftMax [ i ] * rightMax [ i ] , arr [ i ] * leftMin [ i ] * rightMin [ i ] ) ; var max2 = Math . max ( arr [ i ] * leftMax [ i ] * rightMin [ i ] , arr [ i ] * leftMin [ i ] * rightMax [ i ] ) ; max_product = Math . max ( max_product , Math . max ( max1 , max2 ) ) ; } return max_product ; } var arr = [ 1 , 4 , 3 , - 6 , - 7 , 0 ] ; var n = arr . length ; var max = maxProduct ( arr , n ) ; if ( max == - 1 ) document . write ( " " ) ; else document . write ( " " + max ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maxProduct ( arr , n ) { if ( n < 3 ) return - 1 ; var maxA = Number . MIN_VALUE , maxB = Number . MIN_VALUE , maxC = Number . MIN_VALUE ; var minA = Number . MAX_VALUE , minB = Number . MAX_VALUE ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > maxA ) { maxC = maxB ; maxB = maxA ; maxA = arr [ i ] ; } else if ( arr [ i ] > maxB ) { maxC = maxB ; maxB = arr [ i ] ; } else if ( arr [ i ] > maxC ) maxC = arr [ i ] ; if ( arr [ i ] < minA ) { minB = minA ; minA = arr [ i ] ; } else if ( arr [ i ] < minB ) minB = arr [ i ] ; } return Math . max ( minA * minB * maxA , maxA * maxB * maxC ) ; } var arr = [ 1 , - 4 , 3 , - 6 , 7 , 0 ] ; var n = arr . length ; var max = maxProduct ( arr , n ) ; if ( max == - 1 ) document . write ( " " ) ; else document . write ( " " + max ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxAverageRatio ( arr , K ) { var N = arr . length ; var q = [ ] ; for ( var i = 0 ; i < N ; i ++ ) { var extra = ( ( arr [ i ] [ 0 ] + 1 ) / ( arr [ i ] [ 1 ] + 1 ) ) - ( arr [ i ] [ 0 ] / arr [ i ] [ 1 ] ) ; q . push ( [ extra , i ] ) ; } q . sort ( ) ; while ( K -- ) { var i = q [ q . length - 1 ] [ 1 ] ; q . pop ( ) ; arr [ i ] [ 0 ] += 1 ; arr [ i ] [ 1 ] += 1 ; var extra = ( ( arr [ i ] [ 0 ] + 1 ) / ( arr [ i ] [ 1 ] + 1 ) ) - ( arr [ i ] [ 0 ] / arr [ i ] [ 1 ] ) ; q . push ( [ extra , i ] ) ; q . sort ( ) ; } var ans = 0 ; for ( var i = 0 ; i < N ; i ++ ) { ans += ( arr [ i ] [ 0 ] / arr [ i ] [ 1 ] ) ; } return ans / N ; } var arr = [ [ 1 , 2 ] , [ 3 , 5 ] , [ 2 , 2 ] ] ; var K = 2 ; document . write ( maxAverageRatio ( arr , K ) . toFixed ( 6 ) ) ;

Index/key variables: i
Accumulator variables: K, ans, i
Iterator variables: i
Javascript program:
function minMoves ( a , b , K ) { let n = a . length , m = a [ 0 ] . length ; let cntOperations = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( a [ i ] [ j ] != b [ i ] [ j ] ) { cntOperations ++ ; if ( i + K - 1 >= n j + K - 1 >= m ) { return - 1 ; } for ( let p = 0 ; p <= K - 1 ; p ++ ) { for ( let q = 0 ; q <= K - 1 ; q ++ ) { if ( a [ i + p ] [ j + q ] == ' ' ) { a [ i + p ] [ j + q ] = ' ' ; } else { a [ i + p ] [ j + q ] = ' ' ; } } } } } } return cntOperations ; } let A = [ [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] ] ; let B = [ [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' ] ] ; let K = 3 ; document . write ( minMoves ( A , B , K ) ) ;

Index/key variables: i, j
Accumulator variables: cntOperations, i, j, p, q
Iterator variables: i, j, p, q
Javascript program:
function largestPermutation ( arr , N ) { let p = [ ] ; let mx = arr [ 0 ] ; p . push ( arr [ 0 ] ) ; for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] < mx ) p . push ( arr [ i ] ) ; else { p . unshift ( arr [ i ] ) ; mx = arr [ i ] ; } } for ( i of p ) document . write ( i + " " ) ; } let arr = [ 3 , 1 , 2 , 4 ] ; let N = arr . length ; largestPermutation ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maxConsecutiveCnt ( arr ) { let X = 0 ; arr . sort ( function ( a , b ) { return a - b } ) for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] <= ( X + 1 ) ) { X = X + arr [ i ] ; } else { break ; } } return X + 1 ; } let arr = [ 1 , 1 , 1 , 4 ] ; document . write ( maxConsecutiveCnt ( arr ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
const maxLength = ( A , B ) => { let n = A . length ; let maxSize = 0 ; let pre = { } ; let diff = 0 ; pre [ 0 ] = 0 ; for ( let i = 0 ; i < n ; i ++ ) { diff += ( A [ i ] - B [ i ] ) ; if ( ! ( diff in pre ) ) { pre = i + 1 ; } else { maxSize = Math . max ( maxSize , i - pre + 1 ) ; } } return maxSize ; } let A = [ 1 , 2 , 3 , 4 ] ; let B = [ 4 , 3 , 2 , 1 ] ; document . write ( maxLength ( A , B ) ) ;

Index/key variables: i
Accumulator variables: diff, i
Iterator variables: i
Javascript program:
function expand ( idx , A ) { let l = idx - 1 ; let r = idx + 1 ; while ( l >= 0 ) { if ( A [ idx ] > A [ l ] ) { -- l ; } else { break ; } } if ( l < 0 l == idx ) { l = - 2 ; } while ( r < A . length ) { if ( A [ idx ] > A [ r ] ) { ++ r ; } else { break ; } } if ( r >= A . length r == idx ) { r = - 2 ; } return [ l , r ] ; } function minJumps ( N , A ) { let ans = new Array ( N ) . fill ( 0 ) ; let mp = new Map ( ) ; let iToA = new Map ( ) ; let AToi = new Map ( ) ; let big = A [ 0 ] ; for ( let i = 0 ; i < N ; ++ i ) { big = Math . max ( big , A [ i ] ) ; mp . set ( i , expand ( i , A ) ) ; iToA . set ( i , A [ i ] ) ; AToi . set ( A [ i ] , i ) ; } A . sort ( ( a , b ) => - a + b ) ; for ( let i = 0 ; i < A . length ; ++ i ) { let m ; if ( A [ i ] == big ) { let cur = AToi . get ( A [ i ] ) ; ans [ cur ] = 0 ; continue ; } let cur = AToi . get ( A [ i ] ) ; let l = mp . get ( cur ) [ 0 ] ; let r = mp . get ( cur ) [ 1 ] ; if ( l >= 0 && r < N ) { m = Math . min ( ans [ l ] , ans [ r ] ) + 1 ; } else if ( l < 0 && r < N ) { m = ans [ r ] + 1 ; } else if ( l >= 0 && r >= N ) { m = ans [ l ] + 1 ; } ans [ cur ] = m ; } return ans ; } let arr = [ 5 , 1 , 3 , 4 , 7 ] ; let N = arr . length ; let out = minJumps ( N , arr ) ; for ( it of out ) document . write ( it + " " ) ;

Index/key variables: cur, i, idx, l, r
Iterator variables: i
Javascript program:
let prefix_sum_row = new Array ( 50 ) ; for ( let i = 0 ; i < prefix_sum_row . length ; i ++ ) { prefix_sum_row [ i ] = new Array ( 51 ) . fill ( 0 ) ; } let prefix_sum_col = new Array ( 50 ) ; for ( let i = 0 ; i < prefix_sum_col . length ; i ++ ) { prefix_sum_col [ i ] = new Array ( 51 ) . fill ( 0 ) ; } function is_valid ( r , c , size , grid ) { let r_end = r + size , c_end = c + size ; let sum = 0 ; for ( let i = r , j = c ; i < r_end ; i ++ , j ++ ) { sum += grid [ i ] [ j ] ; } for ( let i = r ; i < r_end ; i ++ ) { if ( prefix_sum_row [ i ] [ c_end ] - prefix_sum_row [ i ] != sum ) { return false ; } } for ( let i = c ; i < c_end ; i ++ ) { if ( prefix_sum_col [ r_end ] [ i ] - prefix_sum_col [ r ] [ i ] != sum ) { return false ; } } let ad_sum = 0 ; for ( let i = r , j = c_end - 1 ; i < r_end ; i ++ , j -- ) { ad_sum += grid [ i ] [ j ] ; } return ad_sum == sum ; } function largestSquareValidMatrix ( grid ) { let m = grid . length , n = grid [ 0 ] . length ; for ( let i = 0 ; i < m ; i ++ ) { for ( let j = 1 ; j <= n ; j ++ ) { prefix_sum_row [ i ] [ j ] = prefix_sum_row [ i ] [ j - 1 ] + grid [ i ] [ j - 1 ] ; } } for ( let i = 1 ; i <= m ; i ++ ) { for ( let j = 0 ; j < n ; j ++ ) { prefix_sum_col [ i ] [ j ] = prefix_sum_col [ i - 1 ] [ j ] + grid [ i - 1 ] [ j ] ; } } for ( let size = Math . min ( m , n ) ; size > 1 ; size -- ) { for ( let i = 0 ; i <= m - size ; i ++ ) { for ( let j = 0 ; j <= n - size ; j ++ ) { if ( is_valid ( i , j , size , grid ) ) { return size ; } } } } return 1 ; } let grid = [ [ 7 , 1 , 4 , 5 , 6 ] , [ 2 , 5 , 1 , 6 , 4 ] , [ 1 , 5 , 4 , 3 , 2 ] , [ 1 , 2 , 7 , 3 , 4 ] ] ; document . write ( largestSquareValidMatrix ( grid ) ) ;

Index/key variables: c_end, i, j, r, r_end
Accumulator variables: ad_sum, i, j, size, sum
Iterator variables: i, j, size
Javascript program:
function minimumPossibleProduct ( K ) { let res = 1 ; let range = ( 1 << K ) - 1 ; for ( let i = 0 ; i < K ; i ++ ) { res *= ( range - 1 ) ; } res *= range ; return res ; } let K = 3 ; document . write ( minimumPossibleProduct ( K ) ) ;

Accumulator variables: i, res
Iterator variables: i
Javascript program:
const maximizeSubset = ( arr , N ) => { arr . sort ( ( a , b ) => a - b ) let maxSize = 0 ; let i = 0 ; let j = i + 2 ; while ( i < N - 2 ) { while ( arr [ i ] + arr [ i + 1 ] > arr [ j ] ) { j ++ ; } maxSize = Math . max ( maxSize , j - i ) ; i ++ ; j = Math . max ( j , i + 2 ) ; } return maxSize ; } let arr = [ 2 , 7 , 4 , 1 , 6 , 9 , 5 , 3 ] ; let N = arr . length ; document . write ( maximizeSubset ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Javascript program:
function maxShiftArrayValue ( arr , cap , N ) { let sumVals = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sumVals += arr [ i ] ; } let maxCapacity = 0 ; for ( let i = 0 ; i < N ; i ++ ) { maxCapacity = Math . max ( cap [ i ] , maxCapacity ) ; } return Math . min ( maxCapacity , sumVals ) ; } let arr = [ 2 , 3 ] ; let cap = [ 5 , 6 ] ; let N = arr . length document . write ( maxShiftArrayValue ( arr , cap , N ) ) ;

Index/key variables: i
Accumulator variables: i, sumVals
Iterator variables: i
Javascript program:
function minimumSizeArray ( S , P ) { if ( S == P ) { return 1 ; } for ( let i = 2 ; i <= S ; i ++ ) { let d = i ; if ( ( S / d ) >= Math . pow ( P , 1.0 / d ) ) { return i ; } } return - 1 ; } let S = 5 , P = 6 ; document . write ( minimumSizeArray ( S , P ) ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findVal ( A , B , N ) { let s = new Set ( ) ; for ( let i = 0 ; i < N ; i ++ ) { s . add ( A [ i ] ) ; } A . sort ( function ( a , b ) { return a - b } ) ; B . sort ( function ( a , b ) { return a - b } ) let X = B [ 0 ] - A [ 1 ] ; if ( X <= 0 ) X = B [ 0 ] - A [ 0 ] ; else { for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( s . has ( B [ i ] - X ) == false ) { X = B [ 0 ] - A [ 0 ] ; break ; } } } document . write ( X ) ; } let A = [ 1 , 4 , 3 , 8 ] ; let B = [ 15 , 8 , 11 ] ; let N = A . length ; findVal ( A , B , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function countPoints ( D ) { let count = 0 ; for ( let x = 1 ; x * x < D * D ; x ++ ) { let y = Math . floor ( Math . sqrt ( D * D - x * x ) ) ; if ( x * x + y * y == D * D ) { count += 4 ; } } count += 4 ; return count ; } let D = 5 ; document . write ( countPoints ( D ) ) ;

Accumulator variables: count, x
Iterator variables: x