dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function rev ( str ) { var st = 0 ; var ed = str . length - 1 ; var s = str . split ( " " ) ; while ( st < ed ) { var temp = s [ st ] ; s [ st ] = s [ ed ] ; s [ ed ] = temp ; st ++ ; ed -- ; } return s . join ( ) ; } function check ( a , b , n ) { var i = 0 ; var j = n - 1 ; while ( i < n ) { if ( a [ i ] !== b [ j ] ) break ; i += 1 ; j -= 1 ; var xa = a . substring ( i , j + 1 - i ) ; var xb = b . substring ( i , j + 1 - i ) ; var XA = xa . split ( " " ) ; XA . sort ( ) . reverse ( ) ; var XB = xb . split ( " " ) ; XB . sort ( ) . reverse ( ) ; if ( xa === XA . join ( " " ) || xb === XB . join ( " " ) ) return true ; } return false ; } var a = " " ; var b = " " ; if ( check ( a , b , a . length ) || check ( b , a , a . length ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: ed, i, j, st
Accumulator variables: ed, i, j, st
Javascript program:
function maxEqualIdx ( arr , k ) { arr . sort ( ) ; let prefixSum = new Array ( arr . length + 1 ) . fill ( 0 ) ; prefixSum [ 1 ] = arr [ 0 ] ; for ( let i = 1 ; i < prefixSum . length - 1 ; ++ i ) { prefixSum [ i + 1 ] = prefixSum [ i ] + arr [ i ] ; } let max = arr . length ; let min = 1 ; let ans = 1 ; while ( min <= max ) { let mid = Math . floor ( ( max + min ) / 2 ) ; if ( check ( prefixSum , mid , k , arr ) ) { ans = mid ; min = mid + 1 ; } else { max = mid - 1 ; } } return ans ; } function check ( pSum , len , k , a ) { let i = 0 ; let j = len ; while ( j <= a . length ) { let maxSize = a [ j - 1 ] ; let totalNumbers = maxSize * len ; let currNumbers = pSum [ j ] - pSum [ i ] ; if ( currNumbers + k >= totalNumbers ) { return true ; } else { i ++ ; j ++ ; } } return false ; } let arr = [ 1 , 1 , 1 ] ; let k = 7 ; document . write ( maxEqualIdx ( arr , k ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function productSum ( arr , N ) { let cntOne = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) cntOne ++ ; } return cntOne * ( cntOne - 1 ) / 2 ; } let arr = [ 0 , 1 , 1 , 0 , 1 ] ; let n = arr . length ; document . write ( productSum ( arr , n ) + " " ) ;

Index/key variables: i
Accumulator variables: cntOne, i
Iterator variables: i
Javascript program:
function minDigits ( N , K ) { let digits_num = Math . floor ( Math . log ( N ) / Math . log ( 10 ) + 1 ) ; let temp_sum = 0 ; let temp = digits_num ; let result ; let X , var1 ; let sum = 0 ; let num2 = N ; while ( num2 != 0 ) { sum += num2 % 10 ; num2 = parseInt ( num2 / 10 ) ; } if ( sum <= K ) { X = 0 ; } else { while ( temp > 0 ) { var1 = parseInt ( N / ( Math . pow ( 10 , temp - 1 ) ) ) ; temp_sum += var1 % 10 ; if ( temp_sum >= K ) { var1 = parseInt ( var1 / 10 ) ; var1 ++ ; result = var1 * Math . pow ( 10 , temp ) ; break ; } temp -- ; } X = result - N ; return X ; } } let N = 11 , K = 1 ; document . write ( minDigits ( N , K ) ) ;

Accumulator variables: sum, temp, temp_sum, var1
Javascript program:
function findWays ( nums , S ) { let sum = 0 ; for ( let i = 0 ; i < nums . length ; i ++ ) sum += nums [ i ] ; let memo = new Array ( [ nums . length + 1 ] [ 2 * sum + 1 ] ) ; for ( let i = 0 ; i < nums . length + 1 ; i ++ ) { memo [ i ] = new Array ( 2 * sum + 1 ) ; for ( let j = 0 ; j < 2 * sum + 1 ; j ++ ) { memo [ i ] [ j ] = Number . MIN_VALUE ; } } return dfs ( memo , nums , S , 0 , 0 , sum ) ; } function dfs ( memo , nums , S , curr_sum , index , sum ) { if ( index == nums . length ) { if ( S == curr_sum ) return 1 ; else return 0 ; } if ( memo [ index ] [ curr_sum + sum ] != Number . MIN_VALUE ) { return memo [ index ] [ curr_sum + sum ] ; } let ans = dfs ( memo , nums , index + 1 , curr_sum + nums [ index ] , S , sum ) + dfs ( memo , nums , index + 1 , curr_sum - nums [ index ] , S , sum ) ; memo [ index ] [ curr_sum + sum ] = ans ; return ans ; } let S = 3 ; let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let answer = findWays ( arr , S ) ; document . write ( answer ) ;

Index/key variables: i, index, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function maxUpdated ( arr ) { let h_score = arr [ 0 ] ; let l_score = arr [ 0 ] ; let i = 1 , j = 1 ; for ( let n in arr ) { if ( h_score < arr [ n ] ) { h_score = n ; i ++ ; } if ( l_score > n ) { l_score = n ; j ++ ; } } document . write ( " " ) ; document . write ( " " + i + " " ) ; document . write ( " " ) ; document . write ( " " + j ) ; } let arr = [ 10 , 5 , 20 , 22 ] ; maxUpdated ( arr ) ;

Index/key variables: n
Accumulator variables: i, j
Iterator variables: n
Javascript program:
function farthest_min ( a , n ) { let suffix_min = new Array ( n ) ; suffix_min [ n - 1 ] = a [ n - 1 ] ; for ( let i = n - 2 ; i >= 0 ; i -- ) { suffix_min [ i ] = Math . min ( suffix_min [ i + 1 ] , a [ i ] ) ; } for ( let i = 0 ; i < n ; i ++ ) { let low = i + 1 , high = n - 1 , ans = - 1 ; while ( low <= high ) { let mid = Math . floor ( ( low + high ) / 2 ) ; if ( suffix_min [ mid ] < a [ i ] ) { ans = mid ; low = mid + 1 ; } else high = mid - 1 ; } document . write ( ans + " " ) ; } } let a = [ 3 , 1 , 5 , 2 , 4 ] ; let n = a . length ; farthest_min ( a , n ) ;

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Javascript program:
function printElements ( a , n ) { a = a . sort ( compare ) ; a = reverse ( a ) ; var cnt = 1 ; for ( var i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] != a [ i + 1 ] ) { document . write ( a [ i ] + " " + cnt + " " + " " ) ; cnt = 1 ; } else cnt += 1 ; } document . write ( a [ n - 1 ] + " " + cnt + " " + " " ) ; } function reverse ( a ) { var i , n = a . length , t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } function compare ( a , b ) { if ( a < b ) { return - 1 ; } else if ( a > b ) { return 1 ; } else { return 0 ; } } var a = [ 1 , 1 , 1 , 2 , 3 , 4 , 9 , 9 , 10 ] ; var n = a . length ; printElements ( a , n ) ;

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Javascript program:
const SMALL_N = 1000000 ; const LARGE_N = 1000000000000000 ; function func ( a , b , c , n ) { let res = a * n ; let logVlaue = Math . floor ( Math . log ( n ) / Math . log ( 2 ) ) ; res += b * n * logVlaue ; res += c * ( n * n * n ) ; return res ; } function getPositionInSeries ( a , b , c , k ) { let start = 1 , end = SMALL_N ; if ( c == 0 ) { end = LARGE_N ; } let ans = 0 ; while ( start <= end ) { let mid = parseInt ( ( start + end ) / 2 ) ; let val = func ( a , b , c , mid ) ; if ( val == k ) { ans = mid ; break ; } else if ( val > k ) { end = mid - 1 ; } else { start = mid + 1 ; } } return ans ; } let a = 2 , b = 1 , c = 1 ; let k = 12168587437017 ; document . write ( getPositionInSeries ( a , b , c , k ) ) ;

Accumulator variables: res
Javascript program:
function checkSorted ( n , arr ) { var b = Array ( n ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) b [ i ] = arr [ i ] ; b . sort ( ) ; var ct = 0 ; for ( var i = 0 ; i < n ; i ++ ) if ( arr [ i ] != b [ i ] ) ct ++ ; if ( ct == 0 ct == 2 ) return true ; else return false ; } var arr = [ 1 , 5 , 3 , 4 , 2 ] ; var n = arr . length ; if ( checkSorted ( n , arr ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i
Accumulator variables: ct, i
Iterator variables: i
Javascript program:
function checkIndices ( Arr , N ) { for ( var i = 0 ; i < N - 1 ; i ++ ) { for ( var j = i + 1 ; j < N ; j ++ ) { if ( Arr [ i ] != Arr [ j ] ) { if ( Arr [ Arr [ i ] - 1 ] == Arr [ Arr [ j ] - 1 ] ) return true ; } } } return false ; } var Arr = [ 3 , 2 , 1 , 1 , 4 ] ; var N = Arr . length ; checkIndices ( Arr , N ) ? document . write ( " " ) : document . write ( " " ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function printPairs ( arr , n , sum ) { for ( let i = 0 ; i < n ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] + arr [ j ] == sum ) document . write ( " " + arr [ i ] + " " + arr [ j ] + " " + " " ) ; } let arr = [ 1 , 5 , 7 , - 1 , 5 ] ; let n = arr . length ; let sum = 6 ; printPairs ( arr , n , sum ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function countTripletsLessThanL ( n , L , arr ) { arr . sort ( function ( a , b ) { return a - b } ) ; let ways = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let indexGreater = upper_bound ( arr , 0 , n , arr [ i ] + L ) ; let numberOfElements = indexGreater - ( i + 1 ) ; if ( numberOfElements >= 2 ) { ways += ( numberOfElements * ( numberOfElements - 1 ) / 2 ) ; } } return ways ; } function upper_bound ( a , low , high , element ) { while ( low < high ) { let middle = low + parseInt ( ( high - low ) / 2 , 10 ) ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } let arr = [ 1 , 2 , 3 , 4 ] ; let n = arr . length ; let L = 4 ; let ans = countTripletsLessThanL ( n , L , arr ) ; document . write ( " " + ans ) ;

Index/key variables: i, middle
Accumulator variables: i, ways
Iterator variables: i
Javascript program:
function minSum ( arr , n ) { let sum = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) { let j = i ; while ( j < n && arr [ j ] <= arr [ j - 1 ] ) { arr [ j ] = arr [ j ] + 1 ; j ++ ; } } sum = sum + arr [ i ] ; } return sum ; } let arr = [ 2 , 2 , 3 , 5 , 6 ] ; let n = arr . length ; document . write ( minSum ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Javascript program:
function minSum ( arr , n ) { let sum = arr [ 0 ] , prev = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] <= prev ) { prev = prev + 1 ; sum = sum + prev ; } else { sum = sum + arr [ i ] ; prev = arr [ i ] ; } } return sum ; } let arr = [ 2 , 2 , 3 , 5 , 6 ] ; let n = arr . length ; document . write ( minSum ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function remVowel ( str ) { let al = [ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' ] ; let result = " " ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( ! al . includes ( str [ i ] ) ) { result += str [ i ] ; } } return result ; } let str = " " + " " ; document . write ( remVowel ( str ) ) ;

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function minCostToMakeElementEqual ( a , n ) { let y ; if ( n % 2 == 1 ) y = a [ Math . trunc ( n / 2 ) ] ; else y = Math . trunc ( ( a [ n / 2 ] + a [ ( n - 2 ) / 2 ] ) / 2 ) ; let s = 0 ; for ( let i = 0 ; i < n ; i ++ ) s += Math . abs ( a [ i ] - y ) ; return s ; } let a = [ 1 , 100 , 101 ] ; let n = a . length ; document . write ( minCostToMakeElementEqual ( a , n ) ) ;

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Javascript program:
function isSorted ( arr , n ) { for ( i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) return false ; } return true ; } function sortPoss ( arr , n ) { for ( i = 0 ; i < n ; i ++ ) { var idx = - 1 ; var minVar = arr [ i ] ; var j = i ; while ( j < n ) { if ( arr [ j ] < minVar ) { minVar = arr [ j ] ; idx = j ; } j = j + 2 ; } if ( idx != - 1 ) { var t ; t = arr [ i ] ; arr [ i ] = arr [ idx ] ; arr [ idx ] = t ; } } if ( isSorted ( arr , n ) ) return true ; else return false ; } var arr = [ 3 , 5 , 1 , 2 , 6 ] ; var n = arr . length ; if ( sortPoss ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;

Index/key variables: i, idx, j
Accumulator variables: i
Iterator variables: i
Javascript program:
function sortt ( number ) { var n = number . length ; for ( i = 0 ; i < n ; ++ i ) { for ( j = i + 1 ; j < n ; ++ j ) { if ( number [ i ] > number [ j ] ) { a = number [ i ] ; number [ i ] = number [ j ] ; number [ j ] = a ; } } } } function upperBound ( arr , N , K ) { var l = 0 ; var r = N ; while ( l < r ) { var mid = parseInt ( ( l + r ) / 2 ) ; if ( arr [ mid ] <= K ) { l = mid + 1 ; } else { r = mid ; } } return l ; } function NDivKWithFreq ( arr , N , K ) { sortt ( arr ) ; var i = 0 ; while ( i < N ) { var X = upperBound ( arr , N , arr [ i ] ) ; if ( ( X - i ) > parseInt ( N / 4 ) ) { document . write ( arr [ i ] + " " ) ; } i = X ; } } var arr = [ 1 , 2 , 2 , 6 , 6 , 6 , 6 , 7 , 10 ] ; var N = arr . length ; var K = 4 ; NDivKWithFreq ( arr , N , K ) ;

Index/key variables: i, j, mid
Iterator variables: i, j
Javascript program:
function maxSum ( a , n ) { var count = Array ( n + 1 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) count [ Math . min ( a [ i ] , n ) ] ++ ; var size = 0 ; var ans = 0 ; for ( var k = 1 ; k <= n ; k ++ ) { while ( count [ k ] > 0 && size < k ) { size ++ ; ans += size ; count [ k ] -- ; } ans += k * count [ k ] ; } return ans ; } var arr = [ 3 , 5 , 1 ] ; var n = arr . length ; document . write ( maxSum ( arr , n ) ) ;

Index/key variables: i, k
Accumulator variables: ans, i, k, size
Iterator variables: i, k
Javascript program:
function answerQueries ( arr , n , queries ) { for ( var i = 0 ; i < queries . length ; i ++ ) { var ans = 0 ; var l = queries [ i ] [ 0 ] - 1 ; var r = queries [ i ] [ 1 ] - 1 ; var freq = new Map ( ) ; for ( var j = l ; j <= r ; j ++ ) { if ( freq . has ( arr [ j ] ) ) freq . set ( arr [ j ] , freq . get ( arr [ j ] ) + 1 ) else freq . set ( arr [ j ] , 1 ) } freq . forEach ( ( value , key ) => { ans += ( key * value ) ; } ) ; document . write ( ans + " " ) ; } } var arr = [ 1 , 2 , 1 ] ; var n = arr . length ; var queries = [ [ 1 , 2 ] , [ 1 , 3 ] ] ; answerQueries ( arr , n , queries ) ;

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
let MAX = 26 ; function functions ( str ) { let l = str . length ; let counter1 = [ ] ; let counter2 = [ ] ; for ( let i = 0 ; i < MAX ; i ++ ) { counter1 [ i ] = 0 ; counter2 [ i ] = 0 ; } for ( let i = 0 ; i < l / 2 ; i ++ ) counter1 [ str [ i ] - ' ' ] ++ ; for ( let i = l / 2 ; i < l ; i ++ ) counter2 [ str [ i ] - ' ' ] ++ ; for ( let i = 0 ; i < MAX ; i ++ ) { if ( counter2 [ i ] != counter1 [ i ] ) return true ; } return false ; } let str = " " ; if ( functions ( str ) != 1 ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
let MAX = 26 ; function Function ( str ) { let l = str . length ; let counter = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) counter [ i ] = 0 ; for ( let i = 0 ; i < l / 2 ; i ++ ) counter [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; for ( let i = Math . floor ( l / 2 ) ; i < l ; i ++ ) counter [ str [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] -- ; for ( let i = 0 ; i < MAX ; i ++ ) if ( counter [ i ] != 0 ) return true ; return false ; } let str = " " ; if ( Function ( str ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function minDifferenceAmongMaxMin ( arr , N , K ) { arr . sort ( ( a , b ) => a - b ) ; let res = 2147483647 ; for ( let i = 0 ; i <= ( N - K ) ; i ++ ) { let curSeqDiff = arr [ i + K - 1 ] - arr [ i ] ; res = Math . min ( res , curSeqDiff ) ; } return res ; } let arr = [ 10 , 20 , 30 , 100 , 101 , 102 ] ; let N = arr . length ; let K = 3 ; document . write ( minDifferenceAmongMaxMin ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function getIndexInSortedArray ( arr , n , idx ) { let result = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ idx ] ) result ++ ; if ( arr [ i ] == arr [ idx ] && i < idx ) result ++ ; } return result ; } let arr = [ 3 , 4 , 3 , 5 , 2 , 3 , 4 , 3 , 1 , 5 ] ; let n = arr . length ; let idxOfEle = 5 ; document . write ( getIndexInSortedArray ( arr , n , idxOfEle ) ) ;

Index/key variables: i, idx
Accumulator variables: i, result
Iterator variables: i
Javascript program:
function possible ( x , S , N ) { let minSum = ( x * ( x + 1 ) ) / 2 ; let maxSum = ( x * ( 2 * N - x + 1 ) ) / 2 ; if ( S < minSum S > maxSum ) { return false ; } return true ; } function findPermutation ( N , L , R , S ) { let x = R - L + 1 ; if ( ! possible ( x , S , N ) ) { document . write ( - 1 ) ; return ; } else { let v = [ ] ; for ( let i = N ; i >= 1 ; -- i ) { if ( S - i >= 0 && possible ( x - 1 , S - i , i - 1 ) ) { S = S - i ; x -- ; v . push ( i ) ; } if ( S == 0 ) { break ; } } if ( S != 0 ) { document . write ( - 1 ) ; return ; } let v1 = [ ] ; for ( let i = 1 ; i <= N ; ++ i ) { it = v . includes ( i ) ; if ( ! it ) { v1 . push ( i ) ; } } let j = 0 , f = 0 ; for ( let i = 1 ; i < L ; ++ i ) { document . write ( v1 [ j ] + " " ) ; j ++ ; } for ( let i = L ; i <= R ; ++ i ) { document . write ( v [ f ] + " " ) ; f ++ ; } for ( let i = R + 1 ; i <= N ; ++ i ) { document . write ( v1 [ j ] + " " ) ; j ++ ; } } return ; } let N = 6 , L = 3 , R = 5 , S = 8 ; findPermutation ( N , L , R , S ) ;

Index/key variables: f, j
Accumulator variables: f, j, x
Iterator variables: i
Javascript program:
function skipIndices ( N , T , arr ) { let sum = 0 ; let count = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { let d = sum + arr [ i ] - T ; let k = 0 ; if ( d > 0 ) { for ( let u of [ ... count . keys ( ) ] . reverse ( ) ) { let j = u ; let x = j * count . get ( j ) ; if ( d <= x ) { k += Math . floor ( ( d + j - 1 ) / j ) ; break ; } k += count . get ( j ) ; d -= x ; } } sum += arr [ i ] ; if ( count . has ( arr [ i ] ) ) { count . set ( arr [ i ] , count . get ( i ) + 1 ) } else { count . set ( arr [ i ] , 1 ) } document . write ( k + " " ) ; } } let N = 7 ; let T = 15 ; let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; skipIndices ( N , T , arr ) ;

Index/key variables: i
Accumulator variables: d, i, k, sum
Iterator variables: i, u
Javascript program:
function maxNumPalindrome ( S ) { let i = 0 ; let freq = new Array ( 26 ) . fill ( 0 ) ; let freqPair = 0 ; let len = ( S . length / 3 ) ; while ( i < S . length ) { freq [ S [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; i ++ ; } for ( i = 0 ; i < 26 ; i ++ ) { freqPair += Math . floor ( freq [ i ] / 2 ) ; } return Math . min ( freqPair , len ) ; } let S = " " ; document . write ( maxNumPalindrome ( S ) + " " ) ;

Index/key variables: i
Accumulator variables: freqPair, i
Iterator variables: i
Javascript program:
function height ( s , adj , visited ) { visited [ s ] = 1 ; var h = 0 ; adj [ s ] . forEach ( child => { if ( visited [ child ] == 0 ) { h = Math . max ( h , 1 + height ( child , adj , visited ) ) ; } } ) ; return h ; } function minimumGroups ( adj , N ) { var visited = Array ( N + 1 ) . fill ( 0 ) ; var groups = - 1000000000 ; for ( var i = 1 ; i <= N ; i ++ ) { if ( visited [ i ] == 0 ) { var comHeight ; comHeight = height ( i , adj , visited ) ; groups = Math . max ( groups , comHeight ) ; } } return groups ; } function addEdge ( adj , u , v ) { adj [ u ] . push ( v ) ; adj [ v ] . push ( u ) ; } var N = 5 ; var adj = Array . from ( Array ( N + 1 ) , ( ) => Array ( ) ) addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 3 , 2 ) ; addEdge ( adj , 4 , 3 ) ; document . write ( minimumGroups ( adj , N ) ) ;

Index/key variables: child, i, s, u, v
Accumulator variables: i
Iterator variables: i
Javascript program:
var ans = 0 ; function subsetSum ( c ) { var L = c . length ; var mul = parseInt ( Math . pow ( 2 , L - 1 ) ) ; for ( i = 0 ; i < c . length ; i ++ ) ans += c [ i ] * mul ; } function subsetGen ( arr , i , n , c ) { if ( i == n ) { subsetSum ( c ) ; return ; } subsetGen ( arr , i + 1 , n , c ) ; c . push ( arr [ i ] ) ; subsetGen ( arr , i + 1 , n , c ) ; c . pop ( 0 ) ; } var arr = [ 1 , 1 ] ; var n = arr . length ; var c = [ ] ; subsetGen ( arr , 0 , n , c ) ; document . write ( ans ) ;

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Javascript program:
function getMaxValue ( arr , arr_size ) { let i , first , second ; if ( arr_size < 2 ) { return 0 ; } first = second = Number . MIN_VALUE ; for ( i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second && arr [ i ] != first ) { second = arr [ i ] ; } } if ( second == Number . MIN_VALUE ) { return 0 ; } else { return second ; } } let arr = [ 4 , 5 , 1 , 8 ] ; let n = arr . length ; document . write ( getMaxValue ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function maximumResult ( a , b , c ) { let countOfNegative = 0 ; let sum = a + b + c ; let product = a * b * c ; let largest = Math . max ( a , Math . max ( b , c ) ) ; let smallest = Math . min ( a , Math . min ( b , c ) ) ; if ( a < 0 ) countOfNegative ++ ; if ( b < 0 ) countOfNegative ++ ; if ( c < 0 ) countOfNegative ++ ; switch ( countOfNegative ) { case 0 : return ( sum - largest ) * largest ; case 1 : return ( product / smallest ) + smallest ; case 2 : return ( product / largest ) + largest ; case 3 : return ( sum - smallest ) * smallest ; } } let a = - 2 , b = - 1 , c = - 4 ; document . write ( maximumResult ( a , b , c ) ) ;

Accumulator variables: countOfNegative
Javascript program:
function check ( n , marks ) { let x = Math . max ( ... marks ) ; let bonus = 100 - x ; let c = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( marks [ i ] + bonus >= 50 ) c += 1 ; } return c ; } let n = 5 ; let marks = [ 0 , 21 , 83 , 45 , 64 ] ; document . write ( check ( n , marks ) ) ;

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Javascript program:
function find_sum ( n , k ) { let total_sum = ( n * ( n + 1 ) ) / 2 ; let power = k ; while ( power <= n ) { total_sum -= power ; power *= k ; } return total_sum ; } let n = 11 , k = 2 ; document . write ( find_sum ( n , k ) ) ;

Accumulator variables: power, total_sum
Javascript program:
var MAX = 10000 ; var hashTable = Array ( MAX ) . fill ( 0 ) ; function minOperations ( arr , n ) { arr . sort ( ( a , b ) => a - b ) ; for ( var i = 0 ; i < n ; i ++ ) hashTable [ arr [ i ] ] ++ ; var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( hashTable [ arr [ i ] ] ) { for ( var j = i ; j < n ; j ++ ) if ( arr [ j ] % arr [ i ] == 0 ) hashTable [ arr [ j ] ] = 0 ; res ++ ; } } return res ; } var arr = [ 4 , 6 , 2 , 8 , 7 , 21 , 24 , 49 , 44 ] ; var n = arr . length ; document . write ( minOperations ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Javascript program:
function ifPossible ( arr , n ) { let copy = arr ; copy . sort ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! ( arr [ i ] == copy [ i ] ) && ! ( arr [ n - 1 - i ] == copy [ i ] ) ) return false ; } return true ; } let arr = [ 1 , 7 , 6 , 4 , 5 , 3 , 2 , 8 ] ; let n = arr . length ; if ( ifPossible ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ; ;

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