dhyuti-n/xlcost-variable-roles huggingface dataset:
Javascript program:
function find ( v , n , dest , s ) { if ( n == 1 ) { if ( Math . abs ( v [ 0 ] - dest ) <= 0.0000001 ) { document . write ( s + ( dest ) . toString ( ) + " " ) ; return true ; } return false ; } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { let a = v [ i ] , b = v [ j ] ; let p = s ; v [ i ] = a + b ; v [ j ] = v [ n - 1 ] ; s = ( s + a . toString ( ) + ' ' + b . toString ( ) + " " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; s = p ; v [ i ] = a - b ; v [ j ] = v [ n - 1 ] ; s = ( s + a . toString ( ) + ' ' + b . toString ( ) + " " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; s = p ; v [ i ] = b - a ; v [ j ] = v [ n - 1 ] ; s = ( s + b . toString ( ) + ' ' + a . toString ( ) + " " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; s = p ; v [ i ] = a * b ; v [ j ] = v [ n - 1 ] ; s = ( s + a . toString ( ) + ' ' + b . toString ( ) + " " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; s = p ; if ( b != 0 ) { v [ i ] = a / b ; v [ j ] = v [ n - 1 ] ; s = ( s + a . toString ( ) + ' ' + b . toString ( ) + " " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; } s = p ; if ( a != 0 ) { v [ i ] = b / a ; v [ j ] = v [ n - 1 ] ; s = ( s + b . toString ( ) + ' ' + a . toString ( ) + " " ) ; if ( find ( v , n - 1 , dest , s ) ) return true ; } s = p ; v [ i ] = a ; v [ j ] = b ; } } return false ; } function checkPossibleOperation ( arr , k ) { let s = " " ; if ( ! find ( arr , arr . length , K , s ) ) { document . write ( " " ) ; } } let arr = [ 2 , 0 , 0 , 2 ] ; let K = 4 ; checkPossibleOperation ( arr , K ) ;

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
let N = 9 ; function print ( grid ) { for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) document . write ( grid [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } function isSafe ( grid , row , col , num ) { for ( let x = 0 ; x <= 8 ; x ++ ) if ( grid [ row ] [ x ] == num ) return false ; for ( let x = 0 ; x <= 8 ; x ++ ) if ( grid [ x ] [ col ] == num ) return false ; let startRow = row - row % 3 , startCol = col - col % 3 ; for ( let i = 0 ; i < 3 ; i ++ ) for ( let j = 0 ; j < 3 ; j ++ ) if ( grid [ i + startRow ] [ j + startCol ] == num ) return false ; return true ; } function solveSuduko ( grid , row , col ) { if ( row == N - 1 && col == N ) return true ; if ( col == N ) { row ++ ; col = 0 ; } if ( grid [ row ] [ col ] != 0 ) return solveSuduko ( grid , row , col + 1 ) ; for ( let num = 1 ; num < 10 ; num ++ ) { if ( isSafe ( grid , row , col , num ) ) { grid [ row ] [ col ] = num ; if ( solveSuduko ( grid , row , col + 1 ) ) return true ; } grid [ row ] [ col ] = 0 ; } return false ; } let grid = [ [ 3 , 0 , 6 , 5 , 0 , 8 , 4 , 0 , 0 ] , [ 5 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] , [ 0 , 8 , 7 , 0 , 0 , 0 , 0 , 3 , 1 ] , [ 0 , 0 , 3 , 0 , 1 , 0 , 0 , 8 , 0 ] , [ 9 , 0 , 0 , 8 , 6 , 3 , 0 , 0 , 5 ] , [ 0 , 5 , 0 , 0 , 9 , 0 , 6 , 0 , 0 ] , [ 1 , 3 , 0 , 0 , 0 , 0 , 2 , 5 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 4 ] , [ 0 , 0 , 5 , 2 , 0 , 6 , 3 , 0 , 0 ] ] if ( solveSuduko ( grid , 0 , 0 ) ) print ( grid ) else document . write ( " " )

Index/key variables: col, i, j, row, x
Accumulator variables: i, j, num, row, x
Iterator variables: i, j, num, x
Javascript program:
function printpairs ( arr , sum ) { let s = new Set ( ) ; for ( let i = 0 ; i < arr . length ; ++ i ) { let temp = sum - arr [ i ] ; if ( s . has ( temp ) ) { document . write ( " " + sum + " " + arr [ i ] + " " + temp + " " ) ; } s . add ( arr [ i ] ) ; } } let A = [ 1 , 4 , 45 , 6 , 10 , 8 ] ; let n = 16 ; printpairs ( A , n ) ;

Index/key variables: i
Iterator variables: i
Javascript program:
function power ( x , y , p ) { let res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } function remainder ( n , a , p ) { let ans = a % p ; for ( let i = 1 ; i <= n ; i ++ ) ans = power ( ans , i , p ) ; return ans ; } let A = 2 , N = 1 , P = 2 ; document . write ( remainder ( N , A , P ) + " " ) ;

Accumulator variables: i
Iterator variables: i
Javascript program:
function findMajority ( arr , n ) { var count1 = 0 , count2 = 0 ; var first = 2147483647 , second = 2147483647 ; = var flag = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( first === arr [ i ] ) count1 ++ ; else if ( second === arr [ i ] ) count2 ++ ; else if ( count1 === 0 ) { count1 ++ ; first = arr [ i ] ; } else if ( count2 === 0 ) { count2 ++ ; second = arr [ i ] ; } else { count1 -- ; count2 -- ; } } count1 = 0 ; count2 = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] === first ) count1 ++ ; else if ( arr [ i ] === second ) count2 ++ ; } if ( count1 > n / 3 ) { document . write ( first + " " ) ; flag = 1 ; } if ( count2 > n / 3 ) { document . write ( second + " " ) ; flag = 1 ; } if ( flag === 0 ) { document . write ( " " + " " ) ; } } var arr = [ 2 , 2 , 3 , 1 , 3 , 2 , 1 , 1 ] ; var n = arr . length ; findMajority ( arr , n ) ;

Index/key variables: i
Accumulator variables: count1, count2, i
Iterator variables: i
Javascript program:
class pair { constructor ( first , second ) { this . first = first ; this . second = second ; } } let seg_max = 51 ; let seg_tree = new Array ( seg_max ) ; let n ; function buildMaxTree ( l , r , i , arr ) { if ( l == r ) { seg_tree [ i ] = new pair ( arr [ l ] , l ) ; return seg_tree [ i ] ; } seg_tree [ i ] = max ( buildMaxTree ( l , Math . floor ( ( l + r ) / 2 ) , 2 * i + 1 , arr ) , buildMaxTree ( Math . floor ( ( l + r ) / 2 ) + 1 , r , 2 * i + 2 , arr ) ) ; return seg_tree [ i ] ; } function rangeMax ( l , r , arr , i , sl , sr ) { if ( sr < l sl > r ) return new pair ( Number . MIN_VALUE , - 1 ) ; if ( sl >= l && sr <= r ) return seg_tree [ i ] ; return max ( rangeMax ( l , r , arr , 2 * i + 1 , sl , Math . floor ( ( sl + sr ) / 2 ) ) , rangeMax ( l , r , arr , 2 * i + 2 , Math . floor ( ( sl + sr ) / 2 ) + 1 , sr ) ) ; } function max ( f , s ) { if ( f . first > s . first ) return f ; else return s ; } function maxSumSubarray ( arr , l , r ) { if ( l > r ) return 0 ; let a = rangeMax ( l , r , arr , 0 , 0 , n - 1 ) ; return a . first * ( r - a . second + 1 ) * ( a . second - l + 1 ) + maxSumSubarray ( arr , l , a . second - 1 ) + maxSumSubarray ( arr , a . second + 1 , r ) ; } let arr = [ 1 , 3 , 1 , 7 ] ; n = arr . length ; buildMaxTree ( 0 , n - 1 , 0 , arr ) ; document . write ( maxSumSubarray ( arr , 0 , n - 1 ) ) ;

Index/key variables: i, l
Class/struct names: pair
Javascript program:
function void findFrequencies ( ele ) { var freq = 1 ; var idx = 1 ; var element = ele [ 0 ] ; while ( idx < ele . length ) { if ( ele [ idx - 1 ] == ele [ idx ] ) { freq ++ ; idx ++ ; } else { document . write ( element + " " + freq ) ; element = ele [ idx ] ; idx ++ ; freq = 1 ; } } document . write ( element + " " + freq ) ; } document . write ( " " ) ; findFrequencies ( new var [ ] { 10 , 20 , 30 , 30 , 30 , 40 , 50 , 50 , 50 , 50 , 70 } ) ;

Index/key variables: idx
Accumulator variables: freq, idx
Javascript program:
function magnitude ( arr , N ) { var magnitude = 0 ; for ( var i = 0 ; i < N ; i ++ ) magnitude += arr [ i ] * arr [ i ] ; return Math . sqrt ( magnitude ) ; } function dotProduct ( arr , brr , N ) { var product = 0 ; for ( var i = 0 ; i < N ; i ++ ) product = product + arr [ i ] * brr [ i ] ; return product ; } function angleBetweenVectors ( arr , brr , N ) { var dotProductOfVectors = dotProduct ( arr , brr , N ) ; var magnitudeOfA = magnitude ( arr , N ) ; var magnitudeOfB = magnitude ( brr , N ) ; var angle = dotProductOfVectors / ( magnitudeOfA * magnitudeOfB ) ; document . write ( angle . toFixed ( 6 ) ) ; } var arr = [ - 0.5 , - 2 , 1 ] ; var brr = [ - 1 , - 1 , 0.3 ] ; var N = arr . length ; angleBetweenVectors ( arr , brr , N ) ;

Index/key variables: i
Accumulator variables: i, magnitude
Iterator variables: i
Javascript program:
class Node { constructor ( data ) { this . data = data ; this . left = this . right = this . abtr = null ; } } let even_ptrs = [ ] ; let odd_ptrs = [ ] ; function preorderTraversal ( root ) { if ( root == null ) return ; if ( root . data % 2 == 0 ) ( even_ptrs ) . push ( root ) ; else ( odd_ptrs ) . push ( root ) ; preorderTraversal ( root . left ) ; preorderTraversal ( root . right ) ; } function createLoops ( root ) { preorderTraversal ( root ) ; let i ; for ( i = 1 ; i < even_ptrs . length ; i ++ ) even_ptrs [ i - 1 ] . abtr = even_ptrs [ i ] ; even_ptrs [ i - 1 ] . abtr = even_ptrs [ 0 ] ; for ( i = 1 ; i < odd_ptrs . length ; i ++ ) odd_ptrs [ i - 1 ] . abtr = odd_ptrs [ i ] ; odd_ptrs [ i - 1 ] . abtr = odd_ptrs [ 0 ] ; } function traverseLoop ( start ) { let curr = start ; do { document . write ( curr . data + " " ) ; curr = curr . abtr ; } while ( curr != start ) ; } let root = null ; root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; createLoops ( root ) ; document . write ( " " ) ; traverseLoop ( root . right ) ; document . write ( " " ) ; traverseLoop ( root . left ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Node
Javascript program:
function findVolume ( u , v , w , U , V , W , b ) { let uPow = Math . pow ( u , 2 ) ; let vPow = Math . pow ( v , 2 ) ; let wPow = Math . pow ( w , 2 ) ; let UPow = Math . pow ( U , 2 ) ; let VPow = Math . pow ( V , 2 ) ; let WPow = Math . pow ( W , 2 ) ; let a = 4 * ( uPow * vPow * wPow ) - uPow * Math . pow ( ( vPow + wPow - UPow ) , 2 ) - vPow * Math . pow ( ( wPow + uPow - VPow ) , 2 ) - wPow * Math . pow ( ( uPow + vPow - WPow ) , 2 ) + ( vPow + wPow - UPow ) * ( wPow + uPow - VPow ) * ( uPow + vPow - WPow ) ; let vol = Math . sqrt ( a ) ; vol /= b ; document . write ( vol . toFixed ( 4 ) ) ; } let u = 1000 , v = 1000 , w = 1000 ; let U = 3 , V = 4 , W = 5 ; let b = 12 ; findVolume ( u , v , w , U , V , W , b ) ;

Accumulator variables: vol
Javascript program:
function sq ( x ) { return x * x ; } let EPS = ( 1e-6 ) + 1 ; let N = 5 ; class point { constructor ( x , y ) { this . x = x ; this . y = y ; } } class line { constructor ( a , b , c ) { this . a = a ; this . b = b ; this . c = c ; } } function dist ( x , y , p ) { return Math . sqrt ( sq ( x - p . x ) + sq ( y - p . y ) ) ; } function compute ( p , n , l , X ) { let res = 0 ; let Y = - 1 * ( l . c + l . a * X ) / l . b ; for ( let i = 0 ; i < n ; i ++ ) res += dist ( X , Y , p [ i ] ) ; return res ; } function findOptimumCostUtil ( p , n , l ) { let low = - 1e6 ; let high = 1e6 ; while ( ( high - low ) > EPS ) { let mid1 = low + ( high - low ) / 3 ; let mid2 = high - ( high - low ) / 3 ; let dist1 = compute ( p , n , l , mid1 ) ; let dist2 = compute ( p , n , l , mid2 ) ; if ( dist1 < dist2 ) high = mid2 ; else low = mid1 ; } return compute ( p , n , l , ( low + high ) / 2 ) ; } function findOptimumCost ( points , l ) { let p = new Array ( N ) ; for ( let i = 0 ; i < N ; i ++ ) p [ i ] = new point ( points [ i ] [ 0 ] , points [ i ] [ 1 ] ) ; return findOptimumCostUtil ( p , N , l ) ; } let l = new line ( 1 , - 1 , - 3 ) ; let points = [ [ - 3 , - 2 ] , [ - 1 , 0 ] , [ - 1 , 2 ] , [ 1 , 2 ] , [ 3 , 4 ] ] ; document . write ( findOptimumCost ( points , l ) ) ;

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Class/struct names: line, point
Javascript program:
function findElements ( arr , N ) { let i = 0 ; let missing = [ ] ; let duplicate = new Set ( ) ; while ( i != N ) { if ( arr [ i ] != arr [ arr [ i ] - 1 ] ) { t = arr [ i ] ; arr [ i ] = arr [ arr [ i ] - 1 ] ; arr [ t - 1 ] = t ; } else { i += 1 ; } } for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != i + 1 ) { missing . push ( i + 1 ) ; duplicate . add ( arr [ i ] ) ; } } document . write ( " " ) ; for ( it of missing ) document . write ( it + " " ) ; document . write ( " " ) ; for ( let it of [ ... duplicate ] ) document . write ( it + " " ) ; } let arr = [ 1 , 2 , 2 , 2 , 4 , 5 , 7 ] ; let N = arr . length ; findElements ( arr , N ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i, it
Javascript program:
function factorTree ( N ) { let height = 0 ; while ( N > 1 ) { let flag = false ; for ( let i = 2 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { N = Math . floor ( N / i ) ; flag = true ; break ; } } height ++ ; if ( ! flag ) { break ; } } return height ; } let N = 48 ; document . write ( factorTree ( N ) ) ;

Accumulator variables: height, i
Iterator variables: i
Boolean variables: flag
Javascript program:
let a ; let seg_tree ; let query ; function build_tree ( v , tl , tr ) { if ( tl != tr ) { if ( a [ tl ] == 0 ) seg_tree [ v ] = 1 ; else seg_tree [ v ] = 0 ; } else { let tm = ( tl + tr ) / 2 ; build_tree ( v * 2 , tl , tm ) ; build_tree ( v * 2 + 1 , tm + 1 , tr ) ; seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ] ; } } function frequency_zero ( v , tl , tr , l , r ) { if ( l > r ) return 0 ; if ( l == tl && r == tr ) { return seg_tree [ v ] ; } let tm = ( tl + tr ) / 2 ; return frequency_zero ( v * 2 , tl , tm , l , Math . min ( r , tm ) ) + frequency_zero ( v * 2 + 1 , tm + 1 , tr , Math . max ( l , tm + 1 ) , r ) ; } function update ( v , tl , tr , pos , new_val ) { if ( tl == tr ) { if ( new_val == 0 ) seg_tree [ v ] = 1 ; else seg_tree [ v ] = 0 ; } else { let tm = ( tl + tr ) / 2 ; if ( pos <= tm ) update ( v * 2 , tl , tm , pos , new_val ) ; else update ( v * 2 + 1 , tm + 1 , tr , pos , new_val ) ; seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ] ; } } function solve ( n , q ) { let qu = [ 5 , 3 , 6 ] ; seg_tree = new Array ( 4 * n + 1 ) ; seg_tree . fill ( 0 ) ; build_tree ( 1 , 0 , n - 1 ) ; for ( let i = 0 ; i < qu . length ; i ++ ) { document . write ( qu [ i ] + " " ) ; } for ( let i = q ; i < q ; i ++ ) { if ( query [ i - 1 ] [ 0 ] == 1 ) { let l = query [ i - 1 ] [ 1 ] ; let r = query [ i - 1 ] [ 2 ] ; document . write ( frequency_zero ( 1 , 0 , n - 1 , l , r ) + " " ) ; } else { a [ query [ i - 1 ] [ 1 ] ] = query [ i - 1 ] [ 2 ] ; let pos = query [ i - 1 ] [ 1 ] ; let new_val = query [ i - 1 ] [ 2 ] ; update ( 1 , 0 , n - 1 , pos , new_val ) ; } } } a = [ 9 , 5 , 7 , 6 , 9 , 0 , 0 , 0 , 0 , 5 , 6 , 7 , 3 , 9 , 0 , 7 , 0 , 9 , 0 ] ; let Q = 5 ; query = [ [ 1 , 5 , 14 ] , [ 2 , 6 , 1 ] , [ 1 , 0 , 8 ] , [ 2 , 13 , 0 ] , [ 1 , 6 , 18 ] ] ; let N = a . length ; solve ( N , Q ) ;

Index/key variables: i, tl, v
Accumulator variables: i
Iterator variables: i
Javascript program:
function KnapSack ( val , wt , n , W ) { let mat = new Array ( 2 ) ; for ( let i = 0 ; i < 2 ; i ++ ) { mat [ i ] = new Array ( W + 1 ) ; } for ( let i = 0 ; i < 2 ; i ++ ) { for ( let j = 0 ; j < W + 1 ; j ++ ) { mat [ i ] [ j ] = 0 ; } } let i = 0 ; { if ( i % 2 != 0 ) { { { mat [ 1 ] [ j ] = Math . max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ; { mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ; } } } else { while ( ++ j <= W ) { if ( wt [ i ] <= j ) { mat [ 0 ] [ j ] = Math . max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ; } else { mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ; } } } i ++ ; } return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ; } let val = [ 7 , 8 , 4 ] ; let wt = [ 3 , 8 , 6 ] ; let W = 10 , n = 3 ; document . write ( KnapSack ( val , wt , n , W ) ) ;

Index/key variables: W, i, j
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function Avgdifference ( arr , N , K ) { let min = 1000000 , max = - 1 ; for ( let i = 0 ; i <= N - K ; i ++ ) { let sum = 0 ; for ( let j = 0 ; j < K ; j ++ ) { sum += arr [ i + j ] ; } if ( min > sum ) min = sum ; if ( max < sum ) max = sum ; } return ( max - min ) / K ; } let arr = [ 3 , 8 , 9 , 15 ] ; let N = arr . length ; let K = 2 ; document . write ( Avgdifference ( arr , N , K ) ) ;

Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function MaxRange ( A , n ) { let left = new Array ( n ) . fill ( 0 ) , right = new Array ( n ) . fill ( 0 ) ; let s = [ ] ; s . push ( [ Number . MAX_SAFE_INTEGER , - 1 ] ) ; for ( let i = 0 ; i < n ; i ++ ) { while ( s [ s . length - 1 ] [ 0 ] < A [ i ] ) s . pop ( ) ; left [ i ] = s [ s . length - 1 ] [ 1 ] ; s . push ( [ A [ i ] , i ] ) ; } while ( s . length ) s . pop ( ) ; s . push ( [ Number . MAX_SAFE_INTEGER , n ] ) ; for ( let i = n - 1 ; i >= 0 ; i -- ) { while ( s [ s . length - 1 ] [ 0 ] < A [ i ] ) s . pop ( ) ; right [ i ] = s [ s . length - 1 ] [ 1 ] ; s . push ( [ A [ i ] , i ] ) ; } for ( let i = 0 ; i < n ; i ++ ) { document . write ( left [ i ] + 1 + " " ) document . write ( right [ i ] - 1 + " " ) } } let arr = [ 1 , 3 , 2 ] ; let n = arr . length ; MaxRange ( arr , n ) ;

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Javascript program:
function nthNumber ( n ) { let divs = new Array ( 1000000 ) ; for ( var i = 0 ; i < divs . length ; i ++ ) { divs [ i ] = 0 ; } let vis = new Array ( 1000000 ) ; for ( var i = 0 ; i < vis . length ; i ++ ) { vis [ i ] = 0 ; } let cnt = 0 ; for ( let i = 2 ; cnt < n ; i ++ ) { if ( divs [ i ] == 0 ) { for ( let j = 2 * i ; j < 1000000 ; j += i ) { if ( vis [ j ] ) { continue ; } vis [ j ] = true ; let currNum = j ; let count = 0 ; while ( currNum % i == 0 ) { divs [ j ] ++ ; currNum = Math . floor ( currNum / i ) ; count ++ ; } if ( currNum == 1 && count == 3 && divs [ j ] == 3 ) { cnt ++ ; } else if ( currNum != 1 && divs [ currNum ] == 0 && count == 1 && divs [ j ] == 1 ) { cnt ++ ; } if ( cnt == n ) { return j ; } } } } return - 1 ; } let N = 24 ; document . write ( nthNumber ( N ) ) ;

Index/key variables: currNum, i, j
Accumulator variables: cnt, count, i, j
Iterator variables: i, j
Javascript program:
function findkey ( A , B , C ) { let ans = 0 ; let cur = 1 ; while ( A > 0 ) { let a = A % 10 ; let b = B % 10 ; let c = C % 10 ; A = Math . floor ( A / 10 ) ; B = Math . floor ( B / 10 ) ; C = Math . floor ( C / 10 ) ; let m = Math . max ( a , Math . max ( c , b ) ) ; ans += cur * m ; cur = cur * 10 ; } return ans ; } let A = 3521 , B = 2452 , C = 1352 ; document . write ( findkey ( A , B , C ) ) ;

Accumulator variables: ans
Javascript program:
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function distinctGCDs ( arr , N ) { let M = - 1 , ans = 0 ; var Mp = new Map ( ) ; for ( let i = 0 ; i < N ; i ++ ) { M = Math . max ( M , arr [ i ] ) ; Mp . set ( arr [ i ] , 1 ) ; } for ( let i = 1 ; i <= M ; i ++ ) { let currGcd = 0 ; for ( let j = i ; j <= M ; j += i ) { if ( Mp . has ( j ) ) { currGcd = gcd ( currGcd , j ) ; if ( currGcd == i ) { ans ++ ; break ; } } } } return ans ; } let arr = [ 3 , 11 , 14 , 6 , 12 ] ; let N = arr . length ; document . write ( distinctGCDs ( arr , N ) + ' ' ) ;

Index/key variables: i
Accumulator variables: ans, i, j
Iterator variables: i, j
Javascript program:
function eggDrop ( n , k ) { if ( k == 1 k == 0 ) return k ; if ( n == 1 ) return k ; let min = Number . MAX_VALUE ; let x , res ; for ( x = 1 ; x <= k ; x ++ ) { res = Math . max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ; if ( res < min ) min = res ; } return min + 1 ; } let n = 2 , k = 10 ; document . write ( " " + " " + n + " " + k + " " + eggDrop ( n , k ) ) ;

Accumulator variables: x
Iterator variables: x
Javascript program:
function kthDigitFromLast ( n , k ) { if ( k <= 0 ) { document . write ( - 1 ) ; return ; } while ( ( k - 1 ) > 0 && n > 0 ) { n = n / 10 ; k -- ; } if ( n == 0 ) { document . write ( - 1 ) ; } else { document . write ( parseInt ( n % 10 ) ) ; } } var n = 2354 ; var k = 2 ; kthDigitFromLast ( n , k ) ;

Accumulator variables: k
Javascript program:
function EditDistDP ( str1 , str2 ) { let len1 = str1 . length ; let len2 = str2 . length ; let DP = new Array ( 2 ) ; for ( let i = 0 ; i < 2 ; i ++ ) { DP [ i ] = new Array ( len1 + 1 ) ; for ( let j = 0 ; j < len1 + 1 ; j ++ ) DP [ i ] [ j ] = 0 ; } for ( let i = 0 ; i <= len1 ; i ++ ) DP [ 0 ] [ i ] = i ; for ( let i = 1 ; i <= len2 ; i ++ ) { for ( let j = 0 ; j <= len1 ; j ++ ) { if ( j == 0 ) DP [ i % 2 ] [ j ] = i ; else if ( str1 [ j - 1 ] == str2 [ i - 1 ] ) { DP [ i % 2 ] [ j ] = DP [ ( i - 1 ) % 2 ] [ j - 1 ] ; } else { DP [ i % 2 ] [ j ] = 1 + Math . min ( DP [ ( i - 1 ) % 2 ] [ j ] , Math . min ( DP [ i % 2 ] [ j - 1 ] , DP [ ( i - 1 ) % 2 ] [ j - 1 ] ) ) ; } } } document . write ( DP [ len2 % 2 ] [ len1 ] + " " ) ; } let str1 = " " ; let str2 = " " ; EditDistDP ( str1 , str2 ) ;

Index/key variables: i, j, len1
Accumulator variables: i, j
Iterator variables: i, j
Javascript program:
function xorSumOfArray ( arr , n , k , count ) { var sum = 0 ; var p = 1 ; for ( var i = 0 ; i < 31 ; i ++ ) { var val = 0 ; if ( ( k & ( 1 << i ) ) != 0 ) { var not_set = n - count [ i ] ; val = ( ( not_set ) * p ) ; } else { val = ( count [ i ] * p ) ; } sum += val ; p = ( p * 2 ) ; } return sum ; } function sumOfXors ( arr , n , queries , q ) { var count = new Array ( 32 ) ; count . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < 31 ; j ++ ) { if ( arr [ i ] & ( 1 << j ) ) count [ j ] ++ ; } } for ( var i = 0 ; i < q ; i ++ ) { var k = queries [ i ] ; document . write ( xorSumOfArray ( arr , n , k , count ) + " " ) ; } } var arr = [ 5 , 2 , 3 ] ; var queries = [ 3 , 8 , 7 ] ; var n = arr . length ; var q = queries . length ; sumOfXors ( arr , n , queries , q ) ;

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Javascript program:
function executeProcesses ( A , N , K ) { let pq = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { pq . push ( A [ i ] ) ; } let ans = 0 ; pq . sort ( function ( a , b ) { return a - b ; } ) ; while ( pq . length > 0 && K > 0 ) { let top = pq . pop ( ) ; ans ++ ; K -= top ; top = Math . floor ( top / 2 ) ; pq . push ( top ) ; pq . sort ( function ( a , b ) { return a - b ; } ) ; } document . write ( ans ) } let A = [ 3 , 1 , 7 , 4 , 2 ] ; let K = 15 ; let N = A . length ; executeProcesses ( A , N , K ) ;

Index/key variables: i
Accumulator variables: K, ans, i
Iterator variables: i
Javascript program:
var M = 3 ; var N = 3 ; function findHeightMatrixUtil ( mat , height ) { var q = [ ] ; var vis = Array . from ( Array ( M ) , ( ) => Array ( N ) . fill ( 0 ) ) ; for ( var i = 0 ; i < M ; i ++ ) { for ( var j = 0 ; j < N ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { q . push ( [ i , j ] ) ; height [ i ] [ j ] = 0 ; vis [ i ] [ j ] = 1 ; } } } while ( q . length != 0 ) { var k = q [ 0 ] ; q . shift ( ) ; var x = k [ 0 ] , y = k [ 1 ] ; if ( x > 0 && vis [ x - 1 ] [ y ] == 0 ) { height [ x - 1 ] [ y ] = height [ x ] [ y ] + 1 ; vis [ x - 1 ] [ y ] = 1 ; q . push ( [ x - 1 , y ] ) ; } if ( y > 0 && vis [ x ] [ y - 1 ] == 0 ) { height [ x ] [ y - 1 ] = height [ x ] [ y ] + 1 ; vis [ x ] [ y - 1 ] = 1 ; q . push ( [ x , y - 1 ] ) ; } if ( x < M - 1 && vis [ x + 1 ] [ y ] == 0 ) { height [ x + 1 ] [ y ] = height [ x ] [ y ] + 1 ; vis [ x + 1 ] [ y ] = 1 ; q . push ( [ x + 1 , y ] ) ; } if ( y < N - 1 && vis [ x ] [ y + 1 ] == 0 ) { height [ x ] [ y + 1 ] = height [ x ] [ y ] + 1 ; vis [ x ] [ y + 1 ] = 1 ; q . push ( [ x , y + 1 ] ) ; } } return height ; } function findHeightMatrix ( mat ) { var height = Array . from ( Array ( M ) , ( ) => Array ( N ) . fill ( 0 ) ) ; height = findHeightMatrixUtil ( mat , height ) ; for ( var i = 0 ; i < M ; i ++ ) { for ( var j = 0 ; j < N ; j ++ ) document . write ( height [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } var mat = [ [ 0 , 0 , 0 ] , [ 0 , 1 , 0 ] , [ 0 , 0 , 0 ] ] ; findHeightMatrix ( mat ) ;

Index/key variables: i, j, x, y
Accumulator variables: i, j
Iterator variables: i, j