dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
let V = 5 ; let let_MAX = Number . MAX_VALUE ; function isValidEdge ( u , v , inMST ) { if ( u == v ) return false ; if ( inMST [ u ] == false && inMST [ v ] == false ) return false ; else if ( inMST [ u ] == true && inMST [ v ] == true ) return false ; return true ; } function primMST ( cost ) { let inMST = Array ( V ) . fill ( false ) ; inMST [ 0 ] = true ; let edge_count = 0 , mincost = 0 ; while ( edge_count < V - 1 ) { let min = let_MAX , a = - 1 , b = - 1 ; for ( let i = 0 ; i < V ; i ++ ) { for ( let j = 0 ; j < V ; j ++ ) { if ( cost [ i ] [ j ] < min ) { if ( isValidEdge ( i , j , inMST ) ) { min = cost [ i ] [ j ] ; a = i ; b = j ; } } } } if ( a != - 1 && b != - 1 ) { document . write ( " " + edge_count ++ + " " + a + " " + b + " " + " " + min + " " ) ; mincost = mincost + min ; inMST [ b ] = inMST [ a ] = true ; } } document . write ( " " ) ; document . write ( " " ) ; document . write ( " " + mincost ) ; } let cost = [ [ let_MAX , 2 , let_MAX , 6 , let_MAX ] , [ 2 , let_MAX , 3 , 8 , 5 ] , [ let_MAX , 3 , let_MAX , let_MAX , 7 ] , [ 6 , 8 , let_MAX , let_MAX , 9 ] , [ let_MAX , 5 , 7 , 9 , let_MAX ] ] ; primMST ( cost ) ;

Index/key variables: a, b, i, j, u, v
Accumulator variables: edge_count, i, j
Iterator variables: i, j
Javascript program:
function findLandB ( arr , n ) { arr . sort ( ) ; var arr_pairs = [ ] ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { arr_pairs . push ( arr [ i ] ) ; i ++ ; } } var length = arr_pairs [ 0 ] ; var breadth = arr_pairs [ 1 ] ; var size = arr_pairs . length ; for ( var i = 2 ; i < size ; i ++ ) { if ( ( length / breadth + breadth / length ) > ( arr_pairs [ i ] / arr_pairs [ i - 1 ] + arr_pairs [ i - 1 ] / arr_pairs [ i ] ) ) { length = arr_pairs [ i ] ; breadth = arr_pairs [ i - 1 ] ; } } document . write ( length + " " + breadth ) ; } var arr = [ 4 , 2 , 2 , 2 , 5 , 6 , 5 , 6 , 7 , 2 ] ; var n = arr . length ; findLandB ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function smallestSumSubarr ( arr , n ) { for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = - arr [ i ] ; let sum_here = arr [ 0 ] , max_sum = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { sum_here = Math . max ( sum_here + arr [ i ] , arr [ i ] ) ; max_sum = Math . max ( max_sum , sum_here ) ; } return ( - 1 ) * max_sum ; } let arr = [ 3 , - 4 , 2 , - 3 , - 1 , 7 , - 5 ] ; let n = arr . length ; document . write ( " " + smallestSumSubarr ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function printKPairs ( a1 , a2 , size1 , size2 , k ) { if ( k > ( size2 * size1 ) ) { document . write ( " " ) ; return ; } let _one = [ 0 , 0 ] ; let _two = [ 0 , 0 ] ; let cnt = 0 ; while ( cnt < k ) { if ( _one [ 0 ] == _two [ 1 ] && _two [ 0 ] == _one [ 1 ] ) { if ( a1 [ _one [ 0 ] ] < a2 [ _one [ 1 ] ] ) { document . write ( " " + a1 [ _one [ 0 ] ] + " " + a2 [ _one [ 1 ] ] + " " ) ; _one [ 1 ] = ( _one [ 1 ] + 1 ) % size2 ; if ( _one [ 1 ] == 0 ) _one [ 0 ] = ( _one [ 0 ] + 1 ) % size1 ; _two [ 1 ] = ( _two [ 1 ] + 1 ) % size2 ; if ( _two [ 1 ] == 0 ) _two [ 0 ] = ( _two [ 0 ] + 1 ) % size2 ; } else { document . write ( " " + a2 [ _one [ 1 ] ] + " " + a1 [ _one [ 0 ] ] + " " ) ; _one [ 0 ] = ( _one [ 0 ] + 1 ) % size1 ; if ( _one [ 0 ] == 0 ) _one [ 1 ] = ( _one [ 1 ] + 1 ) % size2 ; _two [ 0 ] = ( _two [ 0 ] + 1 ) % size2 ; if ( _two [ 0 ] == 0 ) _two [ 1 ] = ( _two [ 1 ] + 1 ) % size1 ; } } else if ( a1 [ _one [ 0 ] ] + a2 [ _one [ 1 ] ] <= a2 [ _two [ 0 ] ] + a1 [ _two [ 1 ] ] ) { if ( a1 [ _one [ 0 ] ] < a2 [ _one [ 1 ] ] ) { document . write ( " " + a1 [ _one [ 0 ] ] + " " + a2 [ _one [ 1 ] ] + " " ) ; _one [ 1 ] = ( ( _one [ 1 ] + 1 ) % size2 ) ; if ( _one [ 1 ] == 0 ) _one [ 0 ] = ( _one [ 0 ] + 1 ) % size1 ; } else { document . write ( " " + a2 [ _one [ 1 ] ] + " " + a1 [ _one [ 0 ] ] + " " ) ; _one [ 0 ] = ( ( _one [ 0 ] + 1 ) % size1 ) ; if ( _one [ 0 ] == 0 ) _one [ 1 ] = ( _one [ 1 ] + 1 ) % size2 ; } } else if ( a1 [ _one [ 0 ] ] + a2 [ _one [ 1 ] ] > a2 [ _two [ 0 ] ] + a1 [ _two [ 1 ] ] ) { if ( a2 [ _two [ 0 ] ] < a1 [ _two [ 1 ] ] ) { document . write ( " " + a2 [ _two [ 0 ] ] + " " + a1 [ _two [ 1 ] ] + " " ) ; _two [ 0 ] = ( ( _two [ 0 ] + 1 ) % size2 ) ; if ( _two [ 0 ] == 0 ) _two [ 1 ] = ( _two [ 1 ] + 1 ) % size1 ; } else { document . write ( " " + a1 [ _two [ 1 ] ] + " " + a2 [ _two [ 0 ] ] + " " ) ; _two [ 1 ] = ( ( _two [ 1 ] + 1 ) % size1 ) ; if ( _two [ 1 ] == 0 ) _two [ 0 ] = ( _two [ 0 ] + 1 ) % size1 ; } } cnt ++ ; } } let a1 = [ 2 , 3 , 4 ] ; let a2 = [ 1 , 6 , 5 , 8 ] ; let size1 = a1 . length ; let size2 = a2 . length ; let k = 4 ; printKPairs ( a1 , a2 , size1 , size2 , k ) ;

Accumulator variables: cnt
Javascript program:
function printLargest ( a , n ) { let max = - 1 ; let ind = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { let num = a [ i ] ; while ( num > 0 ) { let r = num % 10 ; num = Math . floor ( num / 10 ) ; if ( num == 0 ) { if ( max < r ) { max = r ; ind = i ; } } } } for ( let i = ind ; i < n ; i ++ ) document . write ( a [ i ] ) ; for ( let i = 0 ; i < ind ; i ++ ) document . write ( a [ i ] ) ; } let a = [ 54 , 546 , 548 , 60 ] ; let n = a . length ; printLargest ( a , 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 construct ( n , ans_pair ) { if ( ans_pair . first == - 1 ) { document . write ( " " ) ; return ; } var a1 = ans_pair . first ; var a2 = ans_pair . second ; var r = a2 / a1 ; document . write ( " " ) ; for ( var i = 1 ; i <= n ; i ++ ) { var ai = parseInt ( a1 * Math . pow ( r , i - 1 ) ) ; document . write ( ai + " " ) ; } } function findMinimumOperations ( a , n ) { var ans = 1000000000 ; var c = [ - 1 , 0 , 1 ] ; var possibilities = 3 ; var pos1 = - 1 , pos2 = - 1 ; for ( var i = 0 ; i < possibilities ; i ++ ) { for ( var j = 0 ; j < possibilities ; j ++ ) { var a1 = a [ 1 ] + c [ i ] ; var a2 = a [ 2 ] + c [ j ] ; var temp = ( Math . abs ( a1 - a [ 1 ] ) + Math . abs ( a2 - a [ 2 ] ) ) ; if ( a1 == 0 a2 == 0 ) continue ; var r = a2 / a1 ; for ( var pos = 3 ; pos <= n ; pos ++ ) { var ai = a1 * Math . pow ( r , pos - 1 ) ; if ( a [ pos ] == ai ) { continue ; } else if ( a [ pos ] + 1 == ai a [ pos ] - 1 == ai ) { temp ++ ; } else { temp = 1000000000 ; break ; } } if ( temp < ans ) { ans = temp ; pos1 = a1 ; pos2 = a2 ; } } } if ( ans == - 1 ) { document . write ( " " ) ; return ; } document . write ( " " + " " + ans + " " ) ; var ans_pair = new pair ( pos1 , pos2 ) ; construct ( n , ans_pair ) ; } var a = [ 0 , 7 , 20 , 49 , 125 ] ; var n = a . length ; findMinimumOperations ( a , n - 1 ) ;

Index/key variables: i, j, pos
Accumulator variables: i, j, pos, temp
Iterator variables: i, j, pos
Class/struct names: pair
Javascript program:
function findOrderMRT ( L , n ) { L . sort ( ) ; document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( L [ i ] + " " ) ; document . write ( " " ) ; let MRT = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let sum = 0 ; for ( let j = 0 ; j <= i ; j ++ ) sum += L [ j ] ; MRT += sum ; } MRT /= n ; document . write ( " " + " " + MRT ) ; } let L = [ 2 , 5 , 4 ] ; let n = L . length ; findOrderMRT ( L , n ) ;

Index/key variables: i, j
Accumulator variables: MRT, i, j, sum
Iterator variables: i, j
Javascript program:
function MinOperation ( a , n , k ) { let result = 0 ; for ( let i = 0 ; i < n ; ++ i ) { if ( a [ i ] != 1 && a [ i ] > k ) { result = result + Math . min ( a [ i ] % k , k - a [ i ] % k ) ; } else { result = result + k - a [ i ] ; } } return result ; } let arr = [ 4 , 5 , 6 ] ; let n = arr . length ; let k = 5 ; document . write ( MinOperation ( arr , n , k ) ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function maxProductSubset ( a , n ) { if ( n == 1 ) return a [ 0 ] ; let max_neg = Number . MIN_SAFE_INTEGER ; let count_neg = 0 ; count_zero = 0 ; let prod = 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { count_zero ++ ; continue ; } if ( a [ i ] < 0 ) { count_neg ++ ; max_neg = Math . max ( max_neg , a [ i ] ) ; } prod = prod * a [ i ] ; } if ( count_zero == n ) return 0 ; if ( count_neg & 1 ) { if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) return 0 ; prod = prod / max_neg ; } return prod ; } let a = [ - 1 , - 1 , - 2 , 4 , 3 ] ; let n = a . length ; document . write ( maxProductSubset ( a , n ) ) ;

Index/key variables: i
Accumulator variables: count_neg, count_zero, i
Iterator variables: i
Javascript program:
function calcFiboTerms ( fiboTerms , K ) { var i = 3 , nextTerm ; fiboTerms . push ( 0 ) ; fiboTerms . push ( 1 ) ; fiboTerms . push ( 1 ) ; while ( 1 ) { nextTerm = fiboTerms [ i - 1 ] + fiboTerms [ i - 2 ] ; if ( nextTerm > K ) return ; fiboTerms . push ( nextTerm ) ; i ++ ; } } function findMinTerms ( K ) { var fiboTerms = [ ] ; calcFiboTerms ( fiboTerms , K ) ; var count = 0 ; var j = fiboTerms . length - 1 ; while ( K > 0 ) { count += parseInt ( K / fiboTerms [ j ] ) ; K %= ( fiboTerms [ j ] ) ; j -- ; } return count ; } var K = 17 ; document . write ( findMinTerms ( K ) ) ;

Index/key variables: j
Accumulator variables: count, i, j
Javascript program:
function digitsNum ( N ) { if ( N == 0 ) document . write ( " " ) ; if ( N % 9 != 0 ) document . write ( N % 9 ) ; for ( var i = 1 ; i <= N / 9 ; ++ i ) document . write ( " " ) ; for ( var i = 1 ; i <= N ; ++ i ) document . write ( " " ) ; document . write ( " " ) ; } var N = 5 ; document . write ( " " ) ; digitsNum ( N ) ;

Iterator variables: i
Javascript program:
function printVector ( v ) { document . write ( v . length + " " ) ; for ( var i = 0 ; i < v . length ; i ++ ) document . write ( v [ i ] + " " ) ; document . write ( " " ) ; } function findTwoGroup ( n ) { var sum = n * ( n + 1 ) / 2 ; var group1Sum = parseInt ( sum / 2 ) ; var group1 = [ ] , group2 = [ ] ; for ( var i = n ; i > 0 ; i -- ) { if ( group1Sum - i >= 0 ) { group1 . push ( i ) ; group1Sum -= i ; } else { group2 . push ( i ) ; } } printVector ( group1 ) ; printVector ( group2 ) ; } var n = 5 ; findTwoGroup ( n ) ;

Index/key variables: i
Accumulator variables: group1Sum, i
Iterator variables: i
Javascript program:
function maxDifference ( arr , N , k ) { let M , S = 0 , S1 = 0 , max_difference = 0 ; for ( let i = 0 ; i < N ; i ++ ) S += arr [ i ] ; let temp ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { if ( arr [ i ] < arr [ j ] ) { temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } } M = Math . max ( k , N - k ) ; for ( let i = 0 ; i < M ; i ++ ) S1 += arr [ i ] ; max_difference = S1 - ( S - S1 ) ; return max_difference ; } let arr = [ 8 , 4 , 5 , 2 , 10 ] ; let N = arr . length ; let k = 2 ; document . write ( maxDifference ( arr , N , k ) ) ;

Index/key variables: i, j
Accumulator variables: S, S1, i, j
Iterator variables: i, j
Javascript program:
function minproduct ( a , b , n , k ) { let diff = 0 , res = 0 ; let temp = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let pro = a [ i ] * b [ i ] ; res = res + pro ; if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ; else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ; else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ; else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ; let d = Math . abs ( pro - temp ) ; if ( d > diff ) diff = d ; } return res - diff ; } let a = [ 2 , 3 , 4 , 5 , 4 ] ; let b = [ 3 , 4 , 2 , 3 , 2 ] ; let n = 5 , k = 3 ; document . write ( minproduct ( a , b , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minRotation ( input , unlock_code ) { let rotation = 0 ; let input_digit , code_digit ; while ( input > 0 unlock_code > 0 ) { input_digit = input % 10 ; code_digit = unlock_code % 10 ; rotation += Math . min ( Math . abs ( input_digit - code_digit ) , 10 - Math . abs ( input_digit - code_digit ) ) ; input = Math . floor ( input / 10 ) ; unlock_code = Math . floor ( unlock_code / 10 ) ; } return rotation ; } let input = 28756 ; let unlock_code = 98234 ; document . write ( " " + minRotation ( input , unlock_code ) ) ;

Accumulator variables: rotation
Javascript program:
function preprocess ( coin , n ) { coin . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 1 ; i <= n - 1 ; i ++ ) coin [ i ] += coin [ i - 1 ] ; } function minCost ( coin , n , k ) { let coins_needed = Math . ceil ( 1.0 * n / ( k + 1 ) ) ; return coin [ coins_needed - 1 ] ; } let coin = [ 8 , 5 , 3 , 10 , 2 , 1 , 15 , 25 ] ; let n = coin . length ; preprocess ( coin , n ) ; let k = 3 ; document . write ( minCost ( coin , n , k ) + " " ) ; k = 7 ; document . write ( minCost ( coin , n , k ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function worstFit ( blockSize , m , processSize , n ) { let allocation = new Array ( n ) ; for ( let i = 0 ; i < allocation . length ; i ++ ) allocation [ i ] = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { let wstIdx = - 1 ; for ( let j = 0 ; j < m ; j ++ ) { if ( blockSize [ j ] >= processSize [ i ] ) { if ( wstIdx == - 1 ) wstIdx = j ; else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ; } } if ( wstIdx != - 1 ) { allocation [ i ] = wstIdx ; blockSize [ wstIdx ] -= processSize [ i ] ; } } document . write ( " " + " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) { document . write ( " " + ( i + 1 ) + " " + " " + processSize [ i ] + " " ) ; if ( allocation [ i ] != - 1 ) document . write ( allocation [ i ] + 1 ) ; else document . write ( " " ) ; document . write ( " " ) ; } } let blockSize = [ 100 , 500 , 200 , 300 , 600 ] ; let processSize = [ 212 , 417 , 112 , 426 ] ; let m = blockSize . length ; let n = processSize . length ; worstFit ( blockSize , m , processSize , n ) ;

Index/key variables: i, j, wstIdx
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function maximumSum ( arr , n , k ) { for ( let i = 1 ; i <= k ; i ++ ) { let min = + 2147483647 ; let index = - 1 ; for ( let j = 0 ; j < n ; j ++ ) { if ( arr [ j ] < min ) { min = arr [ j ] ; index = j ; } } if ( min == 0 ) break ; arr [ index ] = - arr [ index ] ; } let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } let arr = [ - 2 , 0 , 5 , - 1 , 2 ] ; let k = 4 ; let n = arr . length ; document . write ( maximumSum ( arr , n , k ) ) ;

Index/key variables: i, index, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function sol ( arr , k ) { arr . sort ( ) ; let sum = 0 ; let i = 0 ; while ( k > 0 ) { if ( arr [ i ] >= 0 ) k = 0 ; else { arr [ i ] = ( - 1 ) * arr [ i ] ; k = k - 1 ; } i ++ ; } for ( let j = 0 ; j < arr . length ; j ++ ) { sum += arr [ j ] ; } return sum ; } let arr = [ - 2 , 0 , 5 , - 1 , 2 ] ; document . write ( sol ( arr , 4 ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: j
Javascript program:
function sumArray ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } return sum ; } function maximizeSum ( arr , n , k ) { ( arr ) . sort ( function ( a , b ) { return a - b ; } ) ; let i = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( k != 0 && arr [ i ] < 0 ) { arr [ i ] *= - 1 ; k -- ; continue ; } break ; } if ( i == n ) i -- ; if ( k == 0 k % 2 == 0 ) { return sumArray ( arr , n ) ; } if ( i != 0 && Math . abs ( arr [ i ] ) >= Math . abs ( arr [ i - 1 ] ) ) { i -- ; } arr [ i ] *= - 1 ; return sumArray ( arr , n ) ; } let n = 5 ; let k = 4 ; let arr = [ - 3 , - 2 , - 1 , 5 , 6 ] ; document . write ( maximizeSum ( arr , n , k ) ) ;

Index/key variables: i
Accumulator variables: i, k, sum
Iterator variables: i
Javascript program:
function firstFit ( weight , n , c ) { let res = 0 ; let bin_rem = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { let j ; for ( j = 0 ; j < res ; j ++ ) { if ( bin_rem [ j ] >= weight [ i ] ) { bin_rem [ j ] = bin_rem [ j ] - weight [ i ] ; break ; } } if ( j == res ) { bin_rem [ res ] = c - weight [ i ] ; res ++ ; } } return res ; } let weight = [ 2 , 5 , 4 , 7 , 1 , 3 , 8 ] ; let c = 10 ; let n = weight . length ; document . write ( " " + firstFit ( weight , n , c ) ) ;

Index/key variables: i, j, res
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function getMinOperations ( A , B , prevA , prevB , dp ) { if ( A == prevA && B == prevB ) { return Number . MAX_SAFE_INTEGER ; } if ( A == 0 && B == 0 ) { return 0 ; } if ( dp [ A ] [ B ] != - 1 ) { return dp [ A ] [ B ] ; } let ans1 = getMinOperations ( Math . floor ( A / 2 ) , B , A , B , dp ) ; if ( ans1 != Number . MAX_SAFE_INTEGER ) { ans1 += 1 ; } let ans2 = getMinOperations ( A , Math . floor ( B / 2 ) , A , B , dp ) ; if ( ans2 != Number . MAX_SAFE_INTEGER ) { ans2 += 1 ; } let ans3 = getMinOperations ( Math . floor ( Math . sqrt ( A * B ) ) , Math . floor ( Math . sqrt ( A * B ) ) , A , B , dp ) ; if ( ans3 != Number . MAX_SAFE_INTEGER ) { ans3 += 2 ; } return ( dp [ A ] [ B ] = Math . min ( ans1 , Math . min ( ans2 , ans3 ) ) ) ; } let A = 53 , B = 16 ; let mx = Math . max ( A , B ) ; let dp = new Array ( mx + 1 ) . fill ( 0 ) . map ( ( ) => new Array ( mx + 1 ) . fill ( - 1 ) ) ; document . write ( getMinOperations ( A , B , - 1 , - 1 , dp ) ) ;

Index/key variables: A, B
Accumulator variables: ans1, ans2, ans3
Javascript program:
function dfs ( src , visited , graph , component , N ) { visited [ src ] = true ; component . push ( src ) ; for ( let dest = 0 ; dest < N ; dest ++ ) { if ( graph [ src ] [ dest ] != Number . MAX_SAFE_INTEGER ) { if ( ! visited [ dest ] ) dfs ( dest , visited , graph , component , N ) ; } } } function floydWarshall ( graph , N ) { for ( let k = 0 ; k < N ; k ++ ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { if ( graph [ i ] [ k ] != Number . MAX_SAFE_INTEGER && graph [ k ] [ j ] != Number . MAX_SAFE_INTEGER ) { if ( graph [ i ] [ k ] + graph [ k ] [ j ] < graph [ i ] [ j ] ) graph [ i ] [ j ] = graph [ i ] [ k ] + graph [ k ] [ j ] ; } } } } } function maxInThisComponent ( component , graph ) { let maxDistance = Number . MIN_SAFE_INTEGER ; let n = component . length ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { maxDistance = Math . max ( maxDistance , graph [ component [ i ] ] [ component [ j ] ] ) ; } } return maxDistance == Number . MIN_SAFE_INTEGER ? 0 : maxDistance ; } function maximumShortesDistances ( graph , N ) { let visited = new Array ( N ) . fill ( false ) ; let components = new Array ( ) ; let temp = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( ! visited [ i ] ) { temp = [ ] ; dfs ( i , visited , graph , temp , N ) ; components . push ( temp ) ; } } floydWarshall ( graph , N ) ; let result = [ ] ; let numOfComp = components . length ; let maxDistance ; for ( let i = 0 ; i < numOfComp ; i ++ ) { maxDistance = maxInThisComponent ( components [ i ] , graph ) ; result . push ( maxDistance ) ; } return result ; } let N = 8 ; const inf = Number . MAX_SAFE_INTEGER ; let graph1 = [ [ 0 , inf , 9 , inf , inf , inf , 3 , inf ] , [ inf , 0 , inf , 10 , 1 , 8 , inf , inf ] , [ 9 , inf , 0 , inf , inf , inf , 11 , inf ] , [ inf , 10 , inf , 0 , 5 , 13 , inf , inf ] , [ inf , 1 , inf , 5 , 0 , 3 , inf , inf ] , [ 8 , inf , inf , 13 , 3 , 0 , inf , inf ] , [ 3 , inf , 11 , inf , inf , inf , 0 , inf ] , [ inf , inf , inf , inf , inf , inf , inf , 0 ] , ] ; let result1 = maximumShortesDistances ( graph1 , N ) ; for ( mx1 of result1 ) document . write ( mx1 + " " ) ;

Index/key variables: dest, i, j, k, src
Accumulator variables: dest, i, j, k
Iterator variables: dest, i, j, k
Javascript program:
function maxDiffSum ( arr , n ) { let dp = new Array ( n ) . fill ( 0 ) ; for ( let i = 0 ; i < n ; i ++ ) { let maxVal = arr [ i ] , minVal = arr [ i ] ; for ( let j = i ; j >= 0 ; j -- ) { minVal = Math . min ( minVal , arr [ j ] ) ; maxVal = Math . max ( maxVal , arr [ j ] ) ; if ( j - 1 >= 0 ) dp [ i ] = Math . max ( dp [ i ] , maxVal - minVal + dp [ j - 1 ] ) ; else dp [ i ] = Math . max ( dp [ i ] , maxVal - minVal ) ; } } return dp [ n - 1 ] ; } let arr = [ 8 , 1 , 7 , 9 , 2 ] ; let N = arr . length ; document . write ( maxDiffSum ( arr , N ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let MOD = 1000000007 ; function modPow ( x , y ) { let r = 1 , a = x ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) { r = ( r * a ) % MOD ; } a = ( a * a ) % MOD ; y /= 2 ; } return r ; } function modInverse ( x ) { return modPow ( x , MOD - 2 ) ; } function modDivision ( p , q ) { return ( p * modInverse ( q ) ) % MOD ; } function C ( n , k ) { if ( k > n ) { return 0 ; } let p = 1 , q = 1 ; for ( let i = 1 ; i <= k ; i ++ ) { q = ( q * i ) % MOD ; p = ( p * ( n - i + 1 ) ) % MOD ; } return modDivision ( p , q ) ; } function countArrays ( N , K ) { let res = 1 ; for ( let p = 2 ; p <= K / p ; p ++ ) { let c = 0 ; while ( K % p == 0 ) { K /= p ; c ++ ; } res = ( res * C ( N - 1 + c , c ) ) % MOD ; } if ( N > 1 ) { res = ( res * N ) % MOD ; } return res ; } let N = 3 , K = 5 ; document . write ( countArrays ( N , K ) ) ;

Accumulator variables: K, c, i, p, y
Iterator variables: i, p
Javascript program:
function minSessions ( codeTime , dp , ones , n , mask , currTime , WorkingSessionTime ) { if ( currTime > WorkingSessionTime ) return Number . MAX_VALUE ; if ( mask == ones ) return 1 ; if ( dp [ mask ] [ currTime ] != - 1 ) return dp [ mask ] [ currTime ] ; let ans = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( ( mask & ( 1 << i ) ) == 0 ) { let inc = minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , currTime + codeTime [ i ] , WorkingSessionTime ) ; let inc_next = 1 + minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , codeTime [ i ] , WorkingSessionTime ) ; ans = Math . min ( ans , Math . min ( inc , inc_next ) ) ; } } return dp [ mask ] [ currTime ] = ans ; } function solve ( codeTime , n , WorkingSessionTime ) { let dp = new Array ( 1 << 14 ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 15 ) . fill ( - 1 ) ; } let ones = ( 1 << n ) - 1 ; let ans = minSessions ( codeTime , dp , ones , n , 0 , 0 , WorkingSessionTime ) ; if ( WorkingSessionTime < 6 ) { if ( ans % 2 == 0 ) ans = Math . floor ( ans / 2 ) ; else ans = Math . floor ( ans / 2 ) + 1 ; } return ans ; } let codeTime = [ 1 , 2 , 3 , 1 , 1 , 3 ] ; let n = codeTime . length ; let WorkingSessionTime = 4 ; document . write ( solve ( codeTime , n , WorkingSessionTime ) )

Index/key variables: currTime, i, mask
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAXN = 100005 let dp = new Array ( MAXN ) . fill ( new Array ( 10 ) ) ; function solve ( len , gap ) { if ( dp [ len ] [ gap ] != - 1 ) { return dp [ len ] [ gap ] ; } if ( len == 0 gap == 0 ) { return 1 ; } if ( gap < 0 ) { return 0 ; } let ans = 0 ; for ( let i = 0 ; i <= gap ; i ++ ) { ans += solve ( len - 1 , gap - i ) ; } return dp [ len ] [ gap ] = ans ; } function countValidStrings ( S ) { for ( let i = 0 ; i < dp . length ; i ++ ) { for ( let j = 0 ; j < dp [ i ] . length ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } let N = S . length ; let L = 1 , R = 9 ; let cnt = 0 ; let ans = 1 ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] != ' ' ) { R = S . charCodeAt ( i ) - ' ' . charCodeAt ( 0 ) ; ans *= solve ( cnt , R - L ) ; L = R ; R = 9 ; cnt = 0 ; } else { cnt ++ ; } } ans *= solve ( cnt , R - L ) ; return ans ; } let S = " " ; document . write ( countValidStrings ( S ) ) ;

Index/key variables: gap, i, j, len
Accumulator variables: ans, cnt, i, j
Iterator variables: i, j